Skip to content

Instantly share code, notes, and snippets.

@gabrielzanlorenssi
Last active December 18, 2019 19:22
Show Gist options
  • Save gabrielzanlorenssi/a66c7ae0973b5eb599efe50a91fff3cf to your computer and use it in GitHub Desktop.
Save gabrielzanlorenssi/a66c7ae0973b5eb599efe50a91fff3cf to your computer and use it in GitHub Desktop.
#--- libraries
library(readxl)
library(sf)
library(tidyverse)
#--- data
pib <- read_excel("pib.xlsx") %>%
mutate(code = as.numeric(code))
br <- geobr::read_municipality("all", year = 2018)
#--- plot
br %>%
left_join(pib, by=c('code_muni'='code')) %>%
mutate(gdppc2002 = cut(gdppc2002,
breaks=c(-Inf, 5, 10, 15, 20, 25, 30, 50, Inf),
labels=c("<5", "5-10", "10-15", "15-20", "20-25", "25-30", "30-50", ">50")),
gdppc2017 = cut(gdppc2017,
breaks=c(-Inf, 5, 10, 15, 20, 25, 30, 50, Inf),
labels=c("<5", "5-10", "10-15", "15-20", "20-25", "25-30", "30-50", ">50"))) %>%
st_as_sf() %>%
ggplot() +
geom_sf(aes(fill=gdppc2002), col=NA) +
scale_fill_viridis_d(na.value="grey80") +
ggthemes::theme_map()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment