R语言 基于位置和日期创建星星可视化

l7wslrjt  于 2023-01-10  发布在  其他
关注(0)|答案(1)|浏览(135)

背景

我正在努力尝试创建一个天体Map的基础上给定的位置和日期在R。
理想情况下,视觉效果如下所示:
Source

我确实看到了this blog,它利用了D3 Celestial Maps,对创建下面的视觉效果非常有帮助。

library(sf)
library(tidyverse)

theme_nightsky <- function(base_size = 11, base_family = "") {
  
  theme_light(base_size = base_size, base_family = base_family) %+replace% 
    theme(
      # Specify axis options, remove both axis titles and ticks but leave the text in white
      axis.title = element_blank(),
      axis.ticks = element_blank(),
      axis.text = element_text(colour = "white",size=6),
      # Specify legend options, here no legend is needed
      legend.position = "none",
      # Specify background of plotting area
      panel.grid.major = element_line(color = "grey35"),  
      panel.grid.minor = element_line(color = "grey20"),  
      panel.spacing = unit(0.5, "lines"),
      panel.background = element_rect(fill = "black", color  =  NA),  
      panel.border = element_blank(),  
      # Specify plot options
      plot.background = element_rect( fill = "black",color = "black"),  
      plot.title = element_text(size = base_size*1.2, color = "white"),
      plot.margin = unit(rep(1, 4), "lines")
    )
  
}


# Constellations Data
url1 <- "https://raw.githubusercontent.com/ofrohn/d3-celestial/master/data/constellations.lines.json"
# Read in the constellation lines data using the st_read function
constellation_lines_sf <- st_read(url1,stringsAsFactors = FALSE) %>%
                          st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180")) %>% 
                          st_transform(crs = "+proj=moll")

# Stars Data
url2 <- "https://raw.githubusercontent.com/ofrohn/d3-celestial/master/data/stars.6.json"
# Read in the stars way data using the st_read function
stars_sf <- st_read(url2,stringsAsFactors = FALSE) %>% 
            st_transform(crs = "+proj=moll")

ggplot()+
  geom_sf(data=stars_sf, alpha=0.5,color="white")+
  geom_sf(data=constellation_lines_sf, size= 1, color="white")+
  theme_nightsky()

我的问题

我设法在R中创建的图像是(据我所知)整个天体图,我怎样才能得到天体图的一个子集来表示我的相对位置呢?

dgenwo3n

dgenwo3n1#

我认为这里需要一个正投影:

toronto <- "+proj=ortho +lat_0=43 +lon_0=-70"

constellation_lines_sf <- st_read(url1,stringsAsFactors = FALSE) %>%
  st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180")) %>% 
  st_transform(crs = toronto) %>%
  filter(!is.na(st_is_valid(.)))

stars_sf <- st_read(url2,stringsAsFactors = FALSE) %>% 
  st_transform(crs = toronto)

ggplot()+
  geom_sf(data=stars_sf, aes(size = runif(nrow(stars_sf)), 
                             alpha = runif(nrow(stars_sf))),
                             color="white")+
  geom_sf(data=constellation_lines_sf, size= 1, color="white") +
  theme_nightsky() +
  annotation_custom(grid::circleGrob(r = 0.46, gp = grid::gpar( col = "white", 
                                                     lwd = 5, fill = NA))) +
  scale_y_continuous(breaks = seq(0, 90, 15)) +
  scale_size_continuous(range = c(0.2, 1))

相关问题