【问题标题】:How to increase the size of points in legend of ggplot2?如何增加ggplot2图例中点的大小?
【发布时间】:2013-12-23 08:03:39
【问题描述】:

我在一个图中有数千个点并设置“size = 1”。然而,图例中的点大小也减小了。如何增加图例中的磅值?

例如。

num <- 10000
set.seed(1)
df <- data.frame(x = seq(1, num), y = runif(num), z = rep(1:2, each = num / 2))
df$z <- factor(df$z)
library(ggplot2)
p <- ggplot(df, aes(x, y, colour = z)) + geom_point(size = 1)
p

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    在绘图中添加+ guides(colour = guide_legend(override.aes = list(size=10)))。您可以使用 size 参数。

    【讨论】:

    • 如果您想多玩一些设置,请参阅online ggplot2 documentation
    • 如何在我的图例中分别更改colorshape 的大小?尝试以下操作:guides(color = guide_legend(override.aes = list(size=2))) + guides(shape = guide_legend(override.aes = list(size=4))) 产生警告:Warning message: In guide_merge.legend(init, x[[i]]) : Duplicated override.aes is ignored.
    • @theforestecologist - 您可以通过使用 grid 包手动编辑绘图的各个组件来做到这一点。见this answer
    猜你喜欢
    • 1970-01-01
    • 2013-12-22
    • 2020-03-15
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    相关资源
    最近更新 更多