【问题标题】:World map showing day and night regions显示昼夜区域的世界地图
【发布时间】:2018-01-22 14:40:47
【问题描述】:

我正在尝试使用ggplot 在世界地图中添加白天/夜间线以指示白天和黑夜区域;像这样:

计划是像这样在 24 小时周期内为我的地图制作动画:

上面的动画是使用正弦波实现的,我知道这是完全不准确的。我知道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()

虽然我不确定是否可以在一年中的不同时间点绘制所需的线条,例如三月的时候是这样的:


我没有找到解决方案,但我猜我不知道要搜索的关键字,因为这超出了我的知识范围。我认为答案可能在sunrise equation 的某个地方,但我不知道如何应用这些来找到解决方案,也不知道如何在一年中改变这些参数。 This website(用于上图)似乎也很有用,但我还不知道怎么用!

【问题讨论】:

  • This post 可能是对您有帮助的帖子之一。
  • 谢谢@jazzurro - 我以前没看过那个帖子,看起来很有用!
  • 不客气。如果您使用leaflet 包,您可以指示白天和黑夜。我不确定如何制作动画。有兴趣的可以看看this
  • 这也是一个很好的资源,谢谢。了解“终结者”一词也应该有助于找到解决方案!

标签: r ggplot2 gis great-circle geosphere


【解决方案1】:

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

功能可用here

这是一个 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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多