gpt4 book ai didi

r - 如何使图例中的标签在 R 中正确对齐?

转载 作者:行者123 更新时间:2023-12-04 10:59:02 25 4
gpt4 key购买 nike

enter image description here

如图所示,如何使这些标签正确对齐?

我在 R 中使用图例。

最佳答案

来自 ?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)

enter image description here

编辑:

我找不到自动将图例与右侧的线条对齐的方法。但是您可以使用 text 生成图例。放置和选项 bty="n"去除边框。
## similar to above
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, bty="n")

text(4, 2,"lbl1")
text(3.9, 1.92,"mylbl2")

enter image description here

关于r - 如何使图例中的标签在 R 中正确对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32031530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com