5

我有一个情节,我需要连续调整图例。我该怎么做?

plot(x,y)
legend(c("x","y"))

我需要图例应该在一行

    ----- x                 --------- y 

问候

4

1 回答 1

4

你想设置horiz=TRUElegend. 这是默认行为 ( horiz=FALSE) 与horiz=TRUE.

在此处输入图像描述

该图基于文档中的第二个示例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)
于 2014-04-23T14:09:27.103 回答