<Description & Motivation>
- http://rpsychologist.com/working-with-shapefiles-projections-and-world-maps-in-ggplot
- https://stackoverflow.com/questions/10620862/use-different-center-than-the-prime-meridian-in-plotting-a-world-map
- https://gist.github.com/rafapereirabr/9a36c2e5ff04aa285fa3
- https://web.stanford.edu/~cengel/cgi-bin/anthrospace/great-circles-on-a-recentered-worldmap-in-ggplot
- https://rpubs.com/benmschmidt/Recenter
- https://seethedatablog.wordpress.com/2016/12/31/r-shift-centralprime-meridian-of-world-map/
- https://gist.github.com/valentinitnelav/c7598fcfc8e53658f66feea9d3bafb40
library(devtools)
devtools::install_github("thackl/ggworldmap")
library(tidyverse)
library(ggworldmap)
# a nice projected map with graticules and degree labels
ggworldmap(proj = "moll", degree = list("light", long_by = 80))
# and short for
proj <- "moll"
ggplot() +
geom_worldmap(proj = proj, color = "gray90", fill = "gray90") +
geom_graticule(proj = proj, color = "gray80") +
geom_gratframe(proj = proj, color = "gray80") +
geom_degree(proj = proj, color = "gray80", long_by = 80) +
theme_worldmap_light() +
coord_equal()
ggsave("img/ggworldplot.png", width = 12, height = 6, type = "cairo")
# Pacific centered map with colored countries
long_0 <- 110
ggworldmap(proj = "ortho", long_0 = long_0, mapping = aes(fill=group),
long_min = long_0-90, long_max = long_0+90, color = "black",
show.legend = FALSE, graticule = list("light", color = "grey20"),
degree = list("light", long_n = 3, color = "grey30", family = "Times New Roman")) +
scale_fill_distiller(palette = "Pastel2")
ggsave("img/east-asia-countries.png", width = 12, height = 6, type = "cairo")
# The Pacific Ring of Fire
data(volcanic_eruptions) # load example data
proj <- "robin" # Robinson projection
long_0 <- -150 # Center on Pacific
ve_proj <- volcanic_eruptions %>%
project(proj, long_0) %>% # project data
arrange(desc(VEI)) # and get nice plotting order
# plot projected map and data
ggworldmap(ve_proj, long_0 = long_0, proj = proj) +
geom_point(aes(size = VEI^4, color = VEI), alpha =.5) +
scale_color_distiller(palette = "Spectral")
ggsave("img/pacific-ring-of-fire.png", width = 12, height = 6, type = "cairo")
# TODO: Project and Concentrate Data
proj <- "robin" # use Robinson projection
long_0 <- -120 # center on Pacific
lat_min <- -70 # and clip the poles
lat_max <- 70
# get some sample data
data(volcanic_eruptions)
volcanic_eruptions <- volcanic_eruptions %>%
filter(Year > 1919) %>% # let's look at last 100 years
project(proj, long_0) # and we want our data projected
volcanic_eruptions_decluttered <- volcanic_eruptions %>%
concentrate(lambda = .2) %>% # round up close points at a single location
arrange(Type) # and order them nicely for plotting
# set up a plot of the world
gg <- ggplot(mapping = aes(x=long, y=lat)) +
# ----------------------------------------------------------------------------
# get a world map, centered on the Pacific, in Robinson projection
geom_worldmap(proj = proj, long_0 = long_0, lat_min = lat_min,
lat_max = lat_max, color = "grey90", fill = "grey90") +
# add some grid lines
geom_graticule(proj = proj, long_0 = long_0, lat_min = lat_min, lat_max = lat_max,
long_by = 40, linetype = 1, color = "grey80", size = .5, alpha=.3) +
# and a grid frame
geom_graticule(proj = proj, long_0 = long_0, lat_min = lat_min, lat_max = lat_max,
lat_n = 2, long_n = 2, linetype = 1, color = "grey80", size = 1) +
# and some grid labels
geom_degree(proj = proj, long_0 = long_0, lat_min = lat_min, lat_max = lat_max,
long_by = 40, color = "grey60", size = 3)
# ----------------------------------------------------------------------------
# now throw our data on the canvas
geom_array(aes(color = Type), volcanic_eruptions_decluttered, nrow = 7, spread = 2,
shape = 19, size = .8, vjust = .5) +
# original locations with overplotting issues
geom_point(data = volcanic_eruptions, size = .3, alpha = .5) +
# ----------------------------------------------------------------------------
# and finally make things pretty
ggtitle("Significant Volcanic Eruptions", "of the last 100 years by most common types") +
# with fixed aspect ratio, but no poles,
coord_equal(ylim = c(-80, 80)) +
# an almost void greyish theme,
theme_light(base_size = 15) + theme(
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.text = element_blank(), axis.ticks = element_blank(), axis.title = element_blank(),
legend.justification=c(0,1), legend.position=c(.52,.29), legend.text.align=0) +
# and nice colors
scale_color_brewer("Eruption types", palette="Dark2") +
# wrapped in facets
facet_wrap(~Type, ncol=2, strip.position = "left")