Skip to content

Instantly share code, notes, and snippets.

@atbradley
Last active November 5, 2015 12:19
Show Gist options
  • Save atbradley/2900282b45b1b4550596 to your computer and use it in GitHub Desktop.
Save atbradley/2900282b45b1b4550596 to your computer and use it in GitHub Desktop.
Generate a state map using choroplethr and add custom-formatted labels.
c = StateChoropleth$new(df_state_demographics)
c$title = "Population by State, Percent Black"
c$set_num_colors(7)
c$show_labels = F
df_state_labels = data.frame(long = state.center$x, lat =
state.center$y, name=tolower(state.name), label = state.abb)
df_state_labels = df_state_labels[!df_state_labels$name %in% c("alaska",
"hawaii"), ]
d <-c$render() +
geom_text(data = df_state_labels,
aes(long, lat, label = label, group = NULL),
color = gray(.1), size=4)
print(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment