我正在使用 R 中的 tmap 包制作地图。 我正在尝试增加地图内的颜色条,但它不起作用。
您可以在以下链接找到数据:
伦敦行政区边界数据 伦敦边界数据
伦敦便利设施熵数据熵数据
伦敦道路数据 道路数据
以下是我的代码:
# read in london boundary data
boros <- st_read('boros.geojson') %>% st_transform(., 27700)
# read in road data
edges <- st_read('london_all.gpkg', layer = "edges") %>% st_transform(., 27700)
# entropy data
london_entropy_iso <- st_read('london_entropy_iso_500.geojson') %>% st_transform(27700)
#plot the entropy in London
london_entropy_map <-
tm_shape(boros) +
tm_polygons(col = NA, alpha = 0.5) +
tm_shape(edges) +
tm_lines(col = "black",
size = 0.5) +
tm_shape(london_entropy_iso) +
tm_dots(col = 'entropy',
palette = 'viridis',
size = 0.02,
style = 'cont',
title = 'Entropy') +
tm_compass(type = "arrow", position = c('left', 'bottom'), size = 2) +
tm_scale_bar(text.size = 0.9, position = c("left", "bottom")) +
tm_layout(legend.position = c("right", "bottom"),
main.title= "Amenity Diversity Entropy within a 500m Isodistance",
main.title.position = c('center', 'top'),
main.title.size = 3,
frame = FALSE, # Remove the box surrounding the map
inner.margins = 0.1)
# Increase the size of the legend title
london_entropy_map <- london_entropy_map + tm_legend(title.size = 1.5)
# save map
tmap_save(london_entropy_map,
filename = "london_entropy_iso_500_map.png",
width = 16,
height = 20,
dpi = 300)
此代码会生成所附图像。正如您所看到的,右下角的颜色条太小。 我还在 tm_layout() 中添加了“legend.width”和“legend.height”,但它不起作用。
如何增加颜色条的大小?有人可以帮忙吗? 谢谢你。
只需使用
legend.text.size
即可根据您的需要调整色标的大小:
library(tmap)
data(World)
tm_shape(World) +
tm_fill("life_exp", style = "cont", breaks = seq(0, 100, by = 10)) +
tm_layout(legend.text.size = 0.5)
tm_shape(World) +
tm_fill("life_exp", style = "cont", breaks = seq(0, 100, by = 10)) +
tm_layout(legend.text.size = 1)
创建于 2023-08-14,使用 reprex v2.0.2