plot - How to adjust legend in a row in R? -
i have 1 plot , need adjust legends in row. how can it?
plot(x,y) legend(c("x","y"))
i need legend should in 1 line
----- x --------- y
regards
you want set horiz=true
in legend
. here's comparison of default behavior (horiz=false
) horiz=true
.
this plot based on the second example 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)
Comments
Post a Comment