...指定“topright”&将符号放在图例的右侧而不是标签的左侧。
基本上我希望我的传奇位于我的情节右上角的一个方框中,并且我的所有文字都是右对齐的,而不是左对齐。
我的代码处于循环中并应用于100多个图形,因此我试图将图例保留在每个图形的相同位置。
我尝试使用just
和adj
这对我不起作用。
legend("topright", legend=c("data", "data", "data", "data", "data",
"data", "data", "data", "data", "data", "data"),
ncol = 1,
lty = c(1, NA, NA, NA, NA, 1, 1, 1, 2, 2, 2),
pch = c(NA, sym[1], sym[2], sym[2], sym[3], 19, 17, 15, 19, 17, 15),
col = c(blue, aa, aa, aa, aa, gr, bl, pu, gr, bl, pu),
pt.bg = c(NA, a, b, c, d, NA, NA, NA, NA, NA, NA),
pt.cex = c(NA, 1, 1, 1, 1, .5, .5, .5, .5, .5, .5),
cex = .75,
lwd = c(2, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1),
text.col = "black")
答案 0 :(得分:1)
来自?legend
## right-justifying a set of labels: thanks to Uwe Ligges
x <- 1:5; y1 <- 1/x; y2 <- 2/x
plot(rep(x, 2), c(y1, y2), type = "n", xlab = "x", ylab = "y")
lines(x, y1); lines(x, y2, lty = 2)
temp <- legend("topright", legend = c(" ", " "),
text.width = strwidth("1,000,000"),
lty = 1:2, xjust = 1, yjust = 1,
title = "Line Types")
text(temp$rect$left + temp$rect$w, temp$text$y,
c("1,000", "1,000,000"), pos = 2)