Skip to content

R port of the Leaflet.Terminator.js plugin to show day / night regions on a map

Notifications You must be signed in to change notification settings

JoGall/terminator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

terminator

This is a simple R port of the Leaflet plugin Leaflet.Terminator.js intended to indicate day and night regions on a map.

Although this function worked for leaflet maps, I made this function in order to visualise terminators on ggplot maps, such as animations like this:

terminator-animation

Produced like so:

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")

About

R port of the Leaflet.Terminator.js plugin to show day / night regions on a map

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages