【问题标题】:Adjust graph legend in R在 R 中调整图例
【发布时间】:2021-12-08 16:50:24
【问题描述】:

你能帮我调整一下图例吗?图表在正确的位置,但是我希望图例在图表之外,也就是说,图像只需要再降低一点。

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)

示例:

【问题讨论】:

    标签: r plot


    【解决方案1】:

    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)
    

    【讨论】:

    • 谢谢帕克!我根据需要在问题中插入了一张图片
    • @CarlosJoseph 我编辑了代码和绘图的margininset。请检查一下。
    猜你喜欢
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多