Printing too big legend box in RStudio

孤者浪人 提交于 2019-12-05 22:24:44

Just use a keyword instead of specifying the exact coordinates and it will work better:

x <- seq(-pi, pi, len = 65)
plot(x, sin(x), type = "l", col = 2, xlab = expression(phi),
     ylab = expression(f(phi)))
abline(h = -1:1, v = pi/2*(-6:6), col = "gray90")
lines(x, cos(x), col = 3, lty = 2)
ex.cs1 <- expression(plain(sin) * phi,  paste("cos", phi))  # 2 ways
utils::str(legend(-3, .9, ex.cs1, lty = 1:2, plot = FALSE,
                  adj = c(0, 0.6)))  # adj y !
legend('topleft', ex.cs1, lty = 1:2, col = 2:3,  adj = c(0, 0.6))

In this case I used the topleft keyword as you can see and it looks great:

And if you specify cex it does make the legend smaller as you can see below:

x <- seq(-pi, pi, len = 65)
plot(x, sin(x), type = "l", col = 2, xlab = expression(phi),
     ylab = expression(f(phi)))
abline(h = -1:1, v = pi/2*(-6:6), col = "gray90")
lines(x, cos(x), col = 3, lty = 2)
ex.cs1 <- expression(plain(sin) * phi,  paste("cos", phi))  # 2 ways
utils::str(legend(-3, .9, ex.cs1, lty = 1:2, plot = FALSE,
                  adj = c(0, 0.6)))  # adj y !
legend('topleft', ex.cs1, lty = 1:2, col = 2:3,  adj = c(0, 0.6))
legend('topright', ex.cs1, lty = 1:2, col = 2:3,  adj = c(0, 0.6), cex=0.75)

Also, when you look at graphs in Rstudio make sure you hit the zoom button. It is more representative of what the output is.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!