【858】tm_polygons专题地图多图层R语言
ref: tm_polygons: Draw polygons
Arguments
alpha |
transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the |
palette |
a palette name or a vector of colors. See |
breaks |
in case |
midpoint |
The value mapped to the middle color of a diverging palette. By default it is set to 0 if negative and positive values are present. In that case, the two sides of the color palette are assigned to negative respectively positive values. If all values are positive or all values are negative, then the midpoint is set to |
title |
title of the legend element |
legend.show |
logical that determines whether the legend is shown |
popup.vars |
names of data variables that are shown in the popups in 设置为 |
☀☀☀<< 举例 >>☀☀☀
library(tidyverse)
library(sf)
library(ggplot2)
library(tmap)
tmap_mode("view")
# Set default work directory
setwd("/Users/libingnan/Documents/09-Samsung/25-New paper-Hotspot-Monkeypox/Data/socioecnomic_data/world_level_socioeconomic_data")
hist <- st_read("socioeconomic_factors_world.gpkg")
tm_shape(hist, name = "Average Temperature (JAN)") +
tm_polygons("avg_tavgs", title = "Average Temperature", palette = "viridis",
midpoint=NA, popup.vars=TRUE) +
tm_shape(hist, name = "Minimum Temperature (JAN)") +
tm_polygons("avg_tmins", title = "Minimum Temperature", palette = 'viridis',
midpoint=NA, popup.vars=TRUE) +
tm_shape(hist, name = "Maximum Temperature (JAN)") +
tm_polygons("avg_tmaxs", title = "Maximum Temperature", palette = 'viridis',
midpoint=NA, popup.vars=TRUE) +
tm_shape(hist, name = "Elevation") +
tm_polygons("avg_elevs", title = "Elevation", palette = 'Blues',
midpoint=NA, popup.vars=TRUE) +
tm_shape(hist, name = "NDVI (JAN)") +
tm_polygons("avg_ndvis", title = "NDVI", palette = 'Greens',
midpoint=NA, popup.vars=TRUE, breaks = c(0, 40, 80, 120, 160, 200)) +
tm_shape(hist, name = "Precipitation (JAN)") +
tm_polygons("avg_precs", title = "Precipitation", palette = 'Blues',
midpoint=NA, popup.vars=TRUE, breaks = c(0, 80, 160, 240, 320, 400)) +
tm_shape(hist, name = "Water vapor pressure (JAN)") +
tm_polygons("avg_vaprs", title = "Water vapor pressure", palette = 'Oranges',
midpoint=NA, popup.vars=TRUE) +
tm_shape(hist, name = "Wind speed (JAN)") +
tm_polygons("avg_winds", title = "Wind speed", palette = 'Blues',
midpoint=NA, popup.vars=TRUE) +
tm_shape(hist, name = "Solar radiation (JAN)") +
tm_polygons("avg_srads", title = "Solar radiation", palette = 'Oranges',
midpoint=NA, popup.vars=TRUE) +
tm_shape(hist, name = "Population density") +
tm_polygons("pop_est_dens", title = "Population", palette = "Reds",
midpoint=NA, popup.vars=TRUE)

浙公网安备 33010602011771号