一个具有相同比例 tmap 的图例
One legend with same scale tmap
我想把几张图组合成一张图,如附图所示。但我需要创建一个图例(如图所示不是四个)并且还想在 0 到 100 之间变化。
我认为这是可能的,在这方面的任何建议都会很棒。
删除
d_dw <- tm_shape(d_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
title = "Delhi")
卢克
l_dw <- tm_shape(l_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
legend.show = TRUE, title= "Lucknow")
疯狂
m_dw <- tm_shape(m_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
legend.show = TRUE, title = "Madurai")
三
t_dw <- tm_shape(t_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
legend.show = TRUE, title = "Thiruvananthapuram")
tmap_arrange(d_dw, l_dw, m_dw, t_dw, ncol = 2)
您可以为每个 sf
对象添加一个 "categorical" 变量
(例如 d_pcahlsp$place = "Delhi"),将它们与 rbind
绑定
然后使用 `+ tm_facets("place")
制作多面 tmap
在此处使用nc
数据集进行演示:
library(tmap)
library(sf)
# create replicates of the nc dataset
nc <- st_read(system.file("/shape/nc.shp", package="sf"))
nc_2 <- nc
nc_3 <- nc
nc_4 <- nc
# add categorical variable to distinguish "panels,
# and modify the AREA column to see variations
nc$place = "1) Here"
nc_2$place = "2) There"
nc_2$AREA = 1.3 * nc_2$AREA
nc_3$place = "3) And"
nc_3$AREA = 1.1 * nc_3$AREA
nc_4$place = "4) Everywhere"
nc_4$AREA = 0.6 * nc_4$AREA
# bind the datasets
nc_tot <- rbind(nc, nc_2, nc_3, nc_4)
# plot
tm_shape(nc_tot) +
tm_polygons("AREA") +
tm_facets("place", ncol = 2)
我想
删除
d_dw <- tm_shape(d_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
title = "Delhi")
卢克
l_dw <- tm_shape(l_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
legend.show = TRUE, title= "Lucknow")
疯狂
m_dw <- tm_shape(m_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
legend.show = TRUE, title = "Madurai")
三
t_dw <- tm_shape(t_pcahlsp) + tm_fill("dw_twts", breaks=c(0,10, 20, 30,40,50,60, 70, 80, 90, 100), Palette = "Reds",
title = "% Treated drinking water") +
tm_borders(alpha=.4) +
tm_layout(legend.text.size = 0.8, legend.title.size = 0.8, frame = FALSE, legend.outside = TRUE,
legend.show = TRUE, title = "Thiruvananthapuram")
tmap_arrange(d_dw, l_dw, m_dw, t_dw, ncol = 2)
您可以为每个 sf
对象添加一个 "categorical" 变量
(例如 d_pcahlsp$place = "Delhi"),将它们与 rbind
绑定
然后使用 `+ tm_facets("place")
在此处使用nc
数据集进行演示:
library(tmap)
library(sf)
# create replicates of the nc dataset
nc <- st_read(system.file("/shape/nc.shp", package="sf"))
nc_2 <- nc
nc_3 <- nc
nc_4 <- nc
# add categorical variable to distinguish "panels,
# and modify the AREA column to see variations
nc$place = "1) Here"
nc_2$place = "2) There"
nc_2$AREA = 1.3 * nc_2$AREA
nc_3$place = "3) And"
nc_3$AREA = 1.1 * nc_3$AREA
nc_4$place = "4) Everywhere"
nc_4$AREA = 0.6 * nc_4$AREA
# bind the datasets
nc_tot <- rbind(nc, nc_2, nc_3, nc_4)
# plot
tm_shape(nc_tot) +
tm_polygons("AREA") +
tm_facets("place", ncol = 2)