首先:要向tmap添加两个文本标签。添加一个标签效果很好,但第二个标签无法处理
第二:要在第n个字符后换行。
这是我尝试过的:
data(World)
第一个问题:添加多个标签
#Works -> one label
tm_shape(World) +
tm_text("name", size="pop_est", palette="Dark2",
title.size = "Population", title.col="Continent") +
tm_legend(outside = TRUE)
#Does not work -> two labels
tm_shape(World) +
tm_text(c("name", "area"), size="pop_est", palette="Dark2",
title.size = "Population", title.col="Continent") +
tm_legend(outside = TRUE)
第二个问题:自动换行 从这里(R barplot: wrapping long text labels?)使用文本包装器,我得到
##Create a wrapping function in R
wrap.it <- function(x, len)
{
sapply(x, function(y) paste(strwrap(y, len),
collapse = "\n"),
USE.NAMES = FALSE)
}
##Call this function with a list or vector
wrap.labels <- function(x, len)
{
if (is.list(x))
{
lapply(x, wrap.it, len)
} else {
wrap.it(x, len)
}
}
##Plot the data
wr.lap <- wrap.labels(World$name, 3)
tm_shape(World) +
tm_text(wr.lap, size="pop_est", palette="Dark2",
title.size = "Population", title.col="Continent") +
tm_legend(outside = TRUE)
任何帮助,将不胜感激。