tm_text(text, cex = 1, root = 3, fontcolor = NA, fontface = "plain",
fontfamily = "sans", case = NA, bg.color = NA, bg.alpha = 100,
cex.lowerbound = 0.4, print.tiny = FALSE, scale = 1, xmod = 0,
ymod = 0)
AREA
where the text size is proportional to the the area size of the polygons.cex
is a variable name or "AREA"
. If root=2
, the square root is taken, if root=3
the cube root etc.NA
to leave the text as is.bg.color=NA
, so no background is drawn.cex
. Needed to ignore the tiny labels in case cex
is a variable.cex.lowerbound
) are print at size cex.lowerbound
vignette("tmap-nutshell")
}# Europe example
data(Europe)
tm_shape(Europe) +
tm_fill("gdp_cap_est", style="kmeans", textNA = "Non-European countries") +
tm_borders() +
tm_text("iso_a3", cex="AREA", scale=2, bg.alpha=0) +
tm_layout_Europe("GDP per capita")
data(rivers)
data(cities)
tm_shape(Europe) +
tm_fill("pop_est_dens", style="kmeans", textNA="Non-European countries") +
tm_borders() +
tm_shape(rivers) +
tm_lines("dodgerblue3") +
tm_shape(cities) +
tm_text("name", cex="pop_max", scale=1, ymod=-.02, root=4, cex.lowerbound = .60,
bg.color="yellow", bg.alpha = 150) +
tm_bubbles("pop_max", "red", border.col = "black", border.lwd=1, size.lim = c(0, 2e7)) +
tm_shape(Europe) +
tm_text("name", cex="area", scale=1.5, root=8, cex.lowerbound = .40,
fontface="bold", case=NA, fontcolor = "gray35") +
tm_layout_Europe("Map of Europe",
legend.titles = c(fill="Country population density (people per km2)",
bubble.size="City Population"))
Run the code above in your browser using DataLab