[英]Tmap: customize continuous legend values without changing scale
我想在不更改 tmap 中的比例的情况下更改图例的数量。
举个例子:
r <- raster::raster(matrix(runif(100), 10, 10))
tm_shape(r) +
tm_raster(legend.is.portrait = FALSE, style = 'cont', title = '', palette = "-RdBu") +
tm_layout(frame = FALSE, legend.outside = TRUE, legend.outside.position = "bottom")
给我们一个看起来像这样的图例:
我们可以像这样改变 tm_raster 调用中的中断:
tm_shape(r) +
tm_raster(legend.is.portrait = FALSE, style = 'cont', title = '', palette = "-RdBu",
breaks = pretty(cellStats(r, range), 3),) +
tm_layout(frame = FALSE, legend.outside = TRUE, legend.outside.position = "bottom")
这给了我们一个看起来与第一个不同的传说:
我想要做的是在第一个示例中绘制图例,但只有 0.2、0.5 和 0.8 处的标签。
你可以通过一个标签功能的legend.format
的参数tm_layout
。 例如,如果您想要一个标签为 0.2、0.5 和 0.8 的宽图例栏,您可以创建更多中断但只标记您想要的那些:
tm_shape(r) +
tm_raster(legend.is.portrait = FALSE, style = 'cont',
title = '', palette = "-RdBu",
breaks = c(0, 0.2, 0.4, 0.5, 0.6, 0.8, 1)) +
tm_layout(frame = FALSE, legend.outside = TRUE,
legend.outside.position = "bottom",
legend.format = list(fun = function(x) {
ifelse(x %in% c(0.2, 0.5, 0.8), x, "")
}))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.