[英]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.