[英]World map showing day and night regions
I'm trying to add a daytime/nighttime line to a world map using ggplot
in order to indicate day and night regions; 我正在尝试使用ggplot
将日间/夜间线添加到世界地图中,以指示日夜区域; something like this: 这样的事情:
The plan is to animate my map over a 24 hour cycle like this: 计划是在24小时周期内为我的地图制作动画,如下所示:
The above animation is achieved using a sine wave, which I know is totally inaccurate. 上面的动画是用正弦波实现的,我知道它是完全不准确的。 I'm aware that geosphere::gcIntermediate
allows me to draw great-circle lines, like so: 我知道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()
Although I'm not sure if it will be possible to draw the desired lines at different points during the year, eg in March it looks like so: 虽然我不确定是否有可能在一年中的不同点画出所需的线条,例如在三月看起来如此:
I've had no luck finding a solution but am guessing I don't know the keywords to search for as this is way outside my sphere of knowledge. 我没有找到解决方案的运气,但我猜我不知道要搜索的关键字,因为这超出了我的知识范围。 I think the answer may lie somewhere in the sunrise equation , but I've no idea how to apply these to find a solution, nor do I know how to vary these parameters over the course of the year. 我认为答案可能在日出方程中的某处,但我不知道如何应用这些来找到解决方案,我也不知道如何在一年中改变这些参数。 This website (used for the plot above) also seems useful but I'm not yet sure how! 这个网站 (用于上面的情节)似乎也很有用,但我还不确定如何!
I've solved this issue with the help of @jazzurro pointing me to the Leaflet
R package. 我已经在@jazzurro的帮助下解决了这个问题,并指向了Leaflet
R包。 I've ported their javascript plugin, L.Terminator.js , to R in order to use outside of interactive leaflet maps. 我已将他们的javascript插件L.Terminator.js移植到R,以便在交互式传单地图之外使用。
Function is available here . 功能在这里可用。
Here's an example of a 24 hr animation: 这是一个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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.