Created
June 12, 2019 16:11
-
-
Save chrishanretty/133e72e1cd0f35535014b0fca24169d8 to your computer and use it in GitHub Desktop.
Customizing choropleths in R
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
### Load libraries | |
library(ggplot2) | |
### Load data | |
dat <- read.csv("choroData.csv") | |
### Set up the bare plot | |
p <- ggplot(data = dat, | |
aes(x = long, y = lat, group = group, | |
fill = factor(Voucher.count.June.2019))) | |
### Add on the state boundaries | |
p <- p + | |
geom_polygon() | |
### Paint state borders in white | |
p <- p + | |
geom_path(colour = "white") | |
### Chang the fill type (continuous -> discrete) and fill legend | |
p <- p + | |
scale_fill_grey("Voucher count\n(June 2019)") | |
### Set the text elements to be bigger | |
### (You can use a bigger number than 18) | |
p <- p + | |
theme_grey(base_size = 18, | |
base_family = "serif") | |
### Set the background to white | |
p <- p + | |
theme(panel.background = element_rect(fill = "white")) | |
### Remove axes | |
p <- p + | |
theme(axis.title.x = element_blank(), | |
axis.title.y = element_blank(), | |
axis.text.x = element_blank(), | |
axis.text.y = element_blank(), | |
axis.ticks = element_blank()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment