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
To change the Size of Legend, we have to add guides() and guide_legend() functions to the geom_point() function. Inside guides() function, we take parameter color, which calls guide_legend() guide function as value. Inside guide_legend() function, we take an argument called override.
To change the legend size of the plot, the user needs to use the cex argument of the legend function and specify its value with the user requirement, the values of cex greater than 1 will increase the legend size in the plot and the value of cex less than 1 will decrease the size of the legend in the plot.
You can use the following syntax to change the legend labels in ggplot2: p + scale_fill_discrete(labels=c('label1', 'label2', 'label3', ...))
Add a + guides(colour = guide_legend(override.aes = list(size=10)))
to the plot. You can play with the size
argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With