显示日夜区域的世界地图

jog*_*all 13 gis r great-circle ggplot2 geosphere

我正在尝试将日间/夜间线路添加到世界地图ggplot中,以指示日夜区域; 这样的事情:

daynightexample

计划是在24小时的周期内为我的地图制作动画,如下所示:

sinewavetest

上面的动画是用正弦波实现的,我知道它是完全不准确的.我知道这geosphere::gcIntermediate可以让我绘制大圆线,就像这样:

library(ggplot2)
library(ggthemes)
library(geosphere)

sunPath1 <- data.frame(gcIntermediate(c(-179, -30), c(0, 30), n=100))
sunPath2 <- data.frame(gcIntermediate(c(0, 30), c(179, -30), n=100))
sunPath <- rbind(sunPath1, sunPath2)

ggplot(sunPath) +
  borders("world", colour = "gray95", fill = "gray90") +
  geom_ribbon(aes(lon, ymax = lat), ymin=-180, fill="black", alpha=0.2) +
  theme_map()
Run Code Online (Sandbox Code Playgroud)

greatcircletest

虽然我不确定是否有可能在一年中的不同点画出所需的线条,例如在三月看起来如此:

在天上


我没有找到解决方案的运气,但我猜我不知道要搜索的关键字,因为这超出了我的知识范围.我认为答案可能在日出方程中的某处,但我不知道如何应用这些来找到解决方案,我也不知道如何在一年中改变这些参数.这个网站(用于上面的情节)似乎也很有用,但我还不确定如何!

jog*_*all 3

我在 @jazzurro 的帮助下解决了这个问题,指出了LeafletR 包。我已将他们的 javascript 插件L.Terminator.js移植到 R 中,以便在交互式传单地图之外使用。

功能可在此处使用。

以下是 24 小时动画的示例:

library(dplyr)
library(ggplot2)
library(ggthemes)
library(gganimate)
library(animation)

terminatorLatLon <- lapply(seq(0, 23, 1), function(x) {

  t0 <- as.POSIXct(Sys.Date()) + (60*60*x)

  terminator(t0, -180, 190, 0.5) %>%
    mutate(frame = x)
}) %>%
  plyr::rbind.fill()

chart <- ggplot(terminatorLatLon, aes(frame = frame)) +
  borders("world", colour = "gray90", fill = "gray85") +
  geom_ribbon(aes(lat, ymax = lon), ymin = 90, alpha = 0.2) +
  coord_equal(xlim = c(-180, 190), ylim = c(-58, 85), expand = 0) +
  theme_map()

gganimate(chart, interval = 0.1, ani.width=1000, ani.height=600, filename = "terminator-animation.gif")
Run Code Online (Sandbox Code Playgroud)

终结者动画