r - 如何在R中连续调整图例?

标签 r plot legend

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

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

我需要图例应该在一行
    ----- x                 --------- y 

问候

最佳答案

您要设置horiz=TRUElegend .这是默认行为 ( horiz=FALSE ) 与 horiz=TRUE 的比较.

enter image description here

此图基于 the second example from the legend documentation :

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)

关于r - 如何在R中连续调整图例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18326286/

相关文章:

r - 如何提取重复主题 ID 的第二次出现或第一次出现(如果不重复)?

r - 使用 GGPlot 在 R 中创建图例上方的自定义静态标签

R - 使用查找表替换数据框中的值

r - 如何在多层次分析中用不同颜色显示不同层次

r - 如何在 Leaflet for R 中基于 addLayerControl() 隐藏/切换图例

R:将 POSIXct 类分配给数据框

r - 如何以与为箱线图绘制边框相同的方式在 R 中的条形图周围绘制边框

r - ggplot2中离散发散尺度的中点

python - 如何更改 pyplot 中单个图例条目的字体大小?

r - 在图例下方添加其他文本(R + ggplot)