r - 调整 R 中的图形图例

标签 r plot

你能帮我调整图表图例吗?图形处于正确的位置,但是我希望图例位于图形之外,即图像只需进一步降低一点。

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)

enter image description here

示例: enter image description here

最佳答案

legend(...)中,更改inset中的值会有所帮助。

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)

enter image description here

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

相关文章:

r - ggplot : how to break the x-axis into months when data points are per week?

r - 从没有循环的嵌套列表中提取元素

r - R 如何在不调用库的情况下访问包 namespace ?

r - 将数组写入 CSV,col.names = F 的意外行为

regex - R中两个字符之间可变长度单词的正则表达式

r - Visnetwork 图未保存为 png 图像

r - 在散点图上添加 PIL 逊相关系数

python - 如何使用 Python 和 matplotlib 制作 4d 图

r - 按类型打印 data.frame 列和颜色

r - 绘制 lm 返回的模型的结果