Search code examples
rggplot2bubble-chartlegend-properties

ggplot2 - R - How to fix size of bubble in legend


I would like to make the shape that shows the bubble color larger in the legend only. I have tried several suggestions from this site, but I have been unlucky so far. A basic example is below.

In this example, I would like for the "gear" size to be 10. This is probably too large, but I wanted to verify it was working first.

library(ggplot2)
ggplot(mtcars
       ,aes(x=hp, y=disp, size=mpg, fill=factor(gear)))+
geom_point(shape=21)+
theme_bw()+
scale_size_continuous(range=c(2,15))+
guides(shape = guide_legend(override.aes = list(size = 10)))

MT Cars Plot Plot Output


Solution

  • Changing shape to fill in guides will re-scale the size of that element of the legend:

     guides(fill = guide_legend(override.aes = list(size = 10)))