Last active
December 31, 2016 02:01
-
-
Save briatte/c4601cb329006407437fafe5b47aa781 to your computer and use it in GitHub Desktop.
tidykml demo (see comments for the data source and result)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Data + inspiration – U.S. Civil War (Google My Maps)
Result