如何增加ggplot2图例中的点数?


75

我在一个图中有数千个点,并设置为“大小= 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

图例中点的大小

Answers:


152

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


6
如果您想更多地使用这些设置,请参考联机ggplot2文档
Jaap

4
如何更改图例的大小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.
森林生态学家

1
@theforestecologist-您可以通过使用grid软件包手动编辑地块的各个部分来实现。看到这个答案
filups20年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.