[英]Different line length in horizontal legend in R
我想创建一个带有多行(具有不同长度)和每行下方的文本的水平图例。 我有以下代码:
library(RColorBrewer)
colorlevel <- brewer.pal(n = 5, name = 'Set1')
plot.new()
a <- legend("topleft",
legend =c("", "", "", "", "", ""),
lty = 1,
lwd = 4,
bty='o',
seg.len= c(rep(1.5,5), 4),
col = colorlevel,
horiz = TRUE,
trace=TRUE
)
text(a$text$x-0.05, a$text$y, c("A", "B", "C", "D", "E", "F"), pos=1)
这会产生以下图例:
但是,有一些我无法解决的问题:
提前致谢。
试试这个解决方案:
library(RColorBrewer)
colorlevel <- brewer.pal(n = 5, name = 'Set1')
plot.new()
a <- legend("topleft",
legend =c("", "", "", "", "", ""),
lty = 1,
lwd = 3,
bty='o',
seg.len= rep(1.5,5),
col = colorlevel,
horiz = TRUE,
trace=TRUE,
cex = 1.3
)
#you can experiment more with "cex" parameter in legend and text for more accurate output
text(a$text$x-0.06, a$text$y, c("A", "B", "C", "D", "E", "F"), pos=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.