Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smaller gap between two legends in one plot (e.g. color and size scale)

Tags:

how do I reduce the gap between two guides in one plot. In the example below, the two guides are from a color and size scale and I want to change the gap between the two so that the title 'size' is right below the legend-point for 1. Design-wise, it might not make sense in this example but in my actual application it does.

df=data.frame(x=rnorm(100),y=rnorm(100),color=factor(rbinom(100,1,0.5)),size=runif(100)) ggplot(df,aes(x=x,y=y,color=color,size=size)) + geom_point() 

Edit: Here is the plot. I would like to make the gap highlighted by the green line and the arrow smaller.

enter image description here

like image 368
user2503795 Avatar asked Dec 31 '12 16:12

user2503795


1 Answers

Now it seems to be possible using the theme parameters:

ggplot(df,aes(x=x,y=y,color=color,size=size)) + geom_point() +  theme(legend.spacing.y = unit(-0.5, "cm")) 

You can also try to decrease margins of the legends:

legend.margin = margin(-0.5,0,0,0, unit="cm") 

or older

legend.margin=unit(0, "cm") 
like image 51
Melkor.cz Avatar answered Sep 18 '22 22:09

Melkor.cz