Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the size of points in legend of ggplot2?

Tags:

r

ggplot2

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

like image 551
Bangyou Avatar asked Dec 06 '13 04:12

Bangyou


People also ask

How do I make my legend bigger in ggplot2?

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.

How do I increase legend size in R?

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.

How do I change the legend value in ggplot2?

You can use the following syntax to change the legend labels in ggplot2: p + scale_fill_discrete(labels=c('label1', 'label2', 'label3', ...))


1 Answers

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

like image 56
TheComeOnMan Avatar answered Sep 30 '22 11:09

TheComeOnMan