Create a gist now

Instantly share code, notes, and snippets.

@briatte /sherman.r
Last active Dec 31, 2016

What would you like to do?
tidykml demo (see comments for the data source and result)
library(dplyr)
library(ggmap)
library(ggplot2)
library(ggrepel)
# devtools::install_github("briatte/tidykml")
library(tidykml)
f <- system.file("extdata", "states.kml.zip", package = "tidykml")
p <- kml_polygons(f) %>%
filter(name %in% c("Georgia", "South Carolina"))
m <- get_map(kml_bounds(p), source = "osm")
ggmap(m) +
geom_polygon(data = filter(p, name == "Georgia"),
aes(longitude, latitude, group = name, fill = "state"),
alpha = 1/3, color = "white") +
geom_line(data = kml_lines(f),
aes(longitude, latitude),
color = "white", size = 2) +
geom_line(data = kml_lines(f),
aes(longitude, latitude, lty = "march"), size = 1/2) +
geom_point(data = kml_points(f),
aes(longitude, latitude, color = "war"), alpha = 0.5, size = 6) +
geom_label_repel(data = kml_points(f) %>%
mutate(year = gsub("(.*)(\\d{4})", "\\2", name)),
aes(longitude, latitude, label = year),
segment.color = NA, fill = "black", color = "white") +
scale_linetype_manual("", values = c("march" = "solid"),
labels = "Sherman’s March, 1864") +
scale_color_manual("", values = c("war" = "black"),
labels = "Major U.S. Civil War battle") +
scale_fill_manual("", values = c("state" = "darkred"),
labels = "Confederate State of Georgia") +
labs(title = "General Sherman’s March, November 15-December 21, 1864",
subtitle = paste(
"Sherman’s forces marched from Atlanta to Savannah,",
"Georgia, implementing scorched earth policy along the way.")) +
theme(
axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
legend.box = "horizontal",
legend.justification = c(0, 1),
legend.key = element_blank(),
legend.position = "top",
legend.text = element_text(size = rel(1)),
plot.caption = element_text(hjust = 0),
plot.subtitle = element_text(size = rel(1)),
plot.title = element_text(face = "bold")
)
Owner

briatte commented Dec 31, 2016

Data + inspirationU.S. Civil War (Google My Maps)

screen shot 2016-12-31 at 01 56 40

Result

plot_zoom_png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment