Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Created June 12, 2019 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishanretty/133e72e1cd0f35535014b0fca24169d8 to your computer and use it in GitHub Desktop.
Save chrishanretty/133e72e1cd0f35535014b0fca24169d8 to your computer and use it in GitHub Desktop.
Customizing choropleths in R
### 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