101

I have thousands of points in one figure and set size = 1. However, the point size in the legend is reduced too. How to increase the point size in the legend?

For example.

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

The size of points in legend

AndrewGB
  • 12,571
  • 4
  • 13
  • 38
Bangyou
  • 8,880
  • 14
  • 59
  • 90

1 Answers1

207

Add a + guides(colour = guide_legend(override.aes = list(size=10))) to the plot. You can play with the size argument.

TheComeOnMan
  • 11,925
  • 7
  • 36
  • 53
  • 6
    For reference when you want to play a bit more with the settings, see the [online ggplot2 documentation](http://docs.ggplot2.org/current/guide_legend.html) – Jaap Dec 06 '13 at 10:51
  • 6
    How do I change the size of `color` and `shape` separately in my legend? Trying the following: `guides(color = guide_legend(override.aes = list(size=2))) + guides(shape = guide_legend(override.aes = list(size=4)))` produces the warning: `Warning message: In guide_merge.legend(init, x[[i]]) : Duplicated override.aes is ignored.` – theforestecologist May 29 '18 at 23:06
  • 1
    @theforestecologist - you can do this by manually editing individual components of a plot using the `grid` package. See [this answer](https://stackoverflow.com/a/34304453/3174566). – filups21 May 05 '20 at 16:08