knitr::opts_chunk$set(echo = TRUE, fig.width = 9)
Open the tmap repository as RStudio project. Set Knit Directory (via drop-down menu of the Knit button in RStudio) to Project Directory.
library(devtools) load_all() data(World,metro,land) World$pop_class = cut(World$pop_est, breaks = c(0, 10, 100, 1000, Inf) * 1e6, labels = c("Small", "Medium", "Large", "Extra Large")) World$HPI_class = cut(World$HPI, breaks = seq(10, 50, by = 10)) World$well_being_class = cut(World$well_being, breaks = seq(2, 8, by = 2)) World$footprint_class = cut(World$footprint, breaks = seq(0, 16, by = 4)) metro$pop2020_class = cut(metro$pop2020, breaks = c(.5, 1.5, 2.5, 5, 15, 40) * 1e6) Africa = World[World$continent == "Africa", ] tmapV = ifelse(packageVersion("tmap") >= "3.4", "4", "3") txt = function(x) print(grid::grid.text(x, gp = gpar(cex = 3))) v3 = function(e) { if (tmapV == "3") { print(e) } else { txt("Only for tmap 3") } invisible(NULL) } v4 = function(e) { if (tmapV == "4") { print(e) } else { txt("Only for tmap 4") } invisible(NULL) } txt(paste("Loaded tmap version", tmapV))
tm_shape(Africa) + tm_symbols(size = "gdp_cap_est", size.scale = tm_scale_continuous(limits = c(0, 20000), ticks = c(5000,7500, 15000, 20000)))
Africa$x = runif(nrow(Africa), min = 1, max = 3) tm_shape(Africa) + tm_symbols(size = "x", size.scale = tm_scale_continuous_log())
tm_shape(Africa) + tm_symbols(size = "x", size.scale = tm_scale_continuous_log2())
tm_shape(Africa) + tm_symbols(fill = "x", fill.scale = tm_scale_continuous_log())
tm_shape(Africa) + tm_symbols(fill = "gdp_cap_est", fill.scale = tm_scale_continuous_log())
Africa$y = seq(1, 10000, length.out = nrow(Africa)) tm_shape(Africa) + tm_symbols(fill = "y", fill.scale = tm_scale_continuous_log())
tm_shape(Africa) + tm_symbols(fill = "gdp_cap_est", fill.scale = tm_scale_continuous_log1p())
tm_shape(Africa) + tm_symbols(fill = "gdp_cap_est", fill.scale = tm_scale_continuous_log())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.