Could you help me adjust the graph legend. The graph is in the correct position, however I would like the legend to be outside the graph, that is, the image only needs to be lowered a little further.
A <- data.frame(x=rnorm(100, 20, 2), y=rnorm(100, 20, 2))
B <- data.frame(x=rnorm(100, 21, 1), y=rnorm(100, 21, 1))
par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
plot(y ~ x, A, ylim=range(c(A$y, B$y)), xlim=range(c(A$x, B$x)), pch=1,
main="Scatter plot of two groups")
points(y ~ x, B, pch=3)
legend("bottomright",inset=c(-0,-0), legend= 3,title="The number is é:",title.col = "black", cex = 1.2)
CodePudding user response:
In legend(...)
, change value in inset
will helps.
A <- data.frame(x=rnorm(100, 20, 2), y=rnorm(100, 20, 2))
B <- data.frame(x=rnorm(100, 21, 1), y=rnorm(100, 21, 1))
par(mar=c(8.1, 4.1, 4.1, 4.1), xpd=TRUE)
plot(y ~ x, A, ylim=range(c(A$y, B$y)), xlim=range(c(A$x, B$x)), pch=1,
main="Scatter plot of two groups")
points(y ~ x, B, pch=3)
legend("bottomright",inset=c(0,-0.375), legend= 3,title="The number is é:",title.col = "black", cex = 1.2)