alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

【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   McDelfino  阅读(31)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-07-12 【604】Python class __dict__.update的使用
2021-07-12 【603】Python 实现 for 和 if 单行显示
2019-07-12 【425】堆排序方法(二叉堆)优先队列(PQ)
点击右上角即可分享
微信分享提示