[英]How to adjust legend in a row in R?
I have one plot and i need to adjust legends in a row. 我有一个情节,我需要连续调整传说。 How can i do it?
我该怎么做?
plot(x,y)
legend(c("x","y"))
I need legend should be in one line 我需要传奇应该是一行
----- x --------- y
Regards 问候
You want to set horiz=TRUE
in legend
. 您想在
legend
设置horiz=TRUE
。 Here's a comparison of the default behavior ( horiz=FALSE
) to horiz=TRUE
. 这是默认行为(
horiz=FALSE
)与horiz=TRUE
。
This plot is based on the second example from the legend
documentation : 此图基于
legend
文档中的第二个示例 :
layout(matrix(1:2,nrow=1))
# `horiz=FALSE` (default behavior)
plot(x, sin(x), type = "l", ylim = c(-1.2, 1.8), col = 3, lty = 2, main="horiz=FALSE (Default)")
points(x, cos(x), pch = 3, col = 4)
lines(x, tan(x), type = "b", lty = 1, pch = 4, col = 6)
legend(-1, 1.9, c("sin", "cos", "tan"), col = c(3, 4, 6),
text.col = "green4", lty = c(2, -1, 1), pch = c(NA, 3, 4),
merge = TRUE, bg = "gray90")
# `horiz=TRUE`
plot(x, sin(x), type = "l", ylim = c(-1.2, 1.8), col = 3, lty = 2, main="horiz=TRUE")
points(x, cos(x), pch = 3, col = 4)
lines(x, tan(x), type = "b", lty = 1, pch = 4, col = 6)
legend(-1, 1.9, c("sin", "cos", "tan"), col = c(3, 4, 6),
text.col = "green4", lty = c(2, -1, 1), pch = c(NA, 3, 4),
merge = TRUE, bg = "gray90", horiz=TRUE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.