tmap demo documentation . , :
library("readxl")
library("maptools")
library("grid")
library("tmap")
library("tmaptools")
get_US_county_2010_shape <- function() {
dir <- tempdir()
download.file("http://www2.census.gov/geo/tiger/GENZ2010/gz_2010_us_050_00_20m.zip", destfile = file.path(dir, "gz_2010_us_050_00_20m.zip"))
unzip(file.path(dir, "gz_2010_us_050_00_20m.zip"), exdir = dir)
read_shape(file.path(dir, "gz_2010_us_050_00_20m.shp"))
}
US <- get_US_county_2010_shape()
US_cont <- US[!(US$STATE %in% c("02","15","72")),]
US_AK <- US[US$STATE == "02", ]
US_HI <- US[US$STATE == "15",]
US_states <- unionSpatialPolygons(US_cont, IDs=US_cont$STATE)
, :
tmap_mode("plot")
tm_shape(US_cont, projection=2163) +
tm_polygons(border.col = "grey50", border.alpha = .5, title = "", showNA = TRUE) +
tm_shape(US_states) +
tm_borders(lwd=1, col = "black", alpha = .5) +
tm_credits("Data @ Unites States Department of Agriculture\nShape @ Unites States Census Bureau", position = c("right", "bottom")) +
tm_layout(title.position = c("center", "top"),
legend.position = c("right", "bottom"),
frame = FALSE,
inner.margins = c(0.1, 0.1, 0.05, 0.05))
m_AK <- tm_shape(US_AK, projection = 3338) +
tm_polygons(border.col = "grey50", border.alpha = .5, breaks = seq(10, 50, by = 5)) +
tm_layout("Alaska", legend.show = FALSE, bg.color = NA, title.size = 0.8, frame = FALSE)
m_HI <- tm_shape(US_HI, projection = 3759) +
tm_polygons(border.col = "grey50", border.alpha = .5, breaks=seq(10, 50, by = 5)) +
tm_layout(legend.show = FALSE, bg.color=NA, title.position = c("LEFT", "BOTTOM"), title.size = 0.8, frame=FALSE)
print(m_AK, vp=viewport(x= 0.15, y= 0.15, width= 0.3, height= 0.3))
print(m_HI, vp=viewport(x= 0.4, y= 0.1, width= 0.2, height= 0.1))
: https://github.com/mtennekes/tmap/tree/master/demo/USChoropleth