Skip to content

Instantly share code, notes, and snippets.

@fawda123
Created May 12, 2018 20: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 fawda123/6b0af282e7f95ba451e0c7879a13f1cc to your computer and use it in GitHub Desktop.
Save fawda123/6b0af282e7f95ba451e0c7879a13f1cc to your computer and use it in GitHub Desktop.
tmapex
# load libraries
library(sf)
library(maps)
library(tmap)
# get states as sf
states <- st_as_sf(map('state', plot = F, fill = T))
# calculate area, add to states
area <- st_area(states)
area <- as.numeric(area) / 1e6
states$area <- area
# chloropleth from qtm function
qtm(states, fill = "area", text = "ID", fill.title = "State area (km2)", text.size='area') +
tm_layout(legend.outside = T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment