alex_bn_lee

导航

【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 col is used (normally 1).

palette

a palette name or a vector of colors. See tmaptools::palette_explorer() for the named palettes. Use a "-" as prefix to reverse the palette. The default palette is taken from tm_layout's argument aes.palette, which typically depends on the style. The type of palette from aes.palette is automatically determined, but can be overwritten: use "seq" for sequential, "div" for diverging, and "cat" for categorical.

breaks

in case style=="fixed", breaks should be specified. The breaks argument can also be used when style="cont". In that case, the breaks are mapped evenly to the sequential or diverging color palette.

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 NA, which means that the value that corresponds to the middle color class (see style) is mapped to the middle color. Only applies when colis a numeric variable. If it is specified for sequential color palettes (e.g. "Blues"), then this color palette will be treated as a diverging color palette.

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 "view" mode. If convert2density=TRUE, the derived density variable name is suffixed with _density. If NA (default), only aesthetic variables (i.e. specified by col and lwd) are shown). If they are not specified, all variables are shown. Set popup.vars to FALSE to disable popups. When a vector of variable names is provided, the names (if specified) are printed in the popups.

设置为TRUE就可以在点击地图的时候显示所有列的信息

☀☀☀<< 举例 >>☀☀☀

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)

 

posted on 2023-07-12 08:16  McDelfino  阅读(40)  评论(0)    收藏  举报