Skip to content

Instantly share code, notes, and snippets.

@han-tun
Forked from hafen/geofacet_labels.R
Created June 11, 2020 04:16
Show Gist options
  • Save han-tun/b4858bb942254d759df0ec3241a46856 to your computer and use it in GitHub Desktop.
Save han-tun/b4858bb942254d759df0ec3241a46856 to your computer and use it in GitHub Desktop.
library(geofacet)
library(ggplot2)
# original plot
ggplot(election, aes(candidate, votes / 1000000, fill = candidate)) +
geom_col() +
scale_fill_manual(values = c("#4e79a7", "#e15759", "#59a14f")) +
facet_geo(~ state, grid = "us_state_grid2") +
coord_flip() +
ylab("Votes (millions)")
# shrink facet labels
ggplot(election, aes(candidate, votes / 1000000, fill = candidate)) +
geom_col() +
scale_fill_manual(values = c("#4e79a7", "#e15759", "#59a14f")) +
facet_geo(~ state, grid = "us_state_grid2") +
coord_flip() +
ylab("Votes (millions)") +
theme(strip.text.x = element_text(size = 6, margin = margin(0.5, 0, 0.5, 0, "mm")))
# remove facet labels
ggplot(election, aes(candidate, votes / 1000000, fill = candidate)) +
geom_col() +
scale_fill_manual(values = c("#4e79a7", "#e15759", "#59a14f")) +
facet_geo(~ state, grid = "us_state_grid2") +
coord_flip() +
ylab("Votes (millions)") +
theme(strip.background = element_blank(), strip.text.x = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment