Symbols of proportional size in ggplot

Using ggplot to construct proportional-area characters seems to require using sqrt() to achieve true proportionality:

 require(ggplot2) t <- data.frame(x=rep(c(1:5),5), y=rep(c(1:5),each=5), s=round(seq(1,100,length.out=25))) t p <- ggplot(data=t, aes(x=x,y=y)) # direct size-to-variable mapping p + geom_point(aes(size=s), pch=22, fill='#0000FF75', col=NA) + scale_size(range = c(1, 40)) + geom_text(data=t, aes(x=x,y=y,label=s),size=3,vjust=1) # proportional area size-to-variable mapping p + geom_point(aes(size=sqrt(s)), pch=22, fill='#0000FF75', col=NA) + scale_size(range = c(1, 40)) + geom_text(data=t, aes(x=x,y=y,label=s),size=3,vjust=1) 

enter image description here

As you can see, these labels are rooted when I need them to show the source data. We tried to play with the scale_size parameters, but nothing works. Does anyone know about this, or maybe an obscure setting to achieve a proportional display of the size of the area?

Thanks in advance.

+7
source share
1 answer

You can use scale_area instead of scale_size :

 p + geom_point(aes(size=s), pch=22, fill='#0000FF75', col=NA) + scale_area(range = c(1, 40)) + geom_text(data=t, aes(x=x,y=y,label=s),size=3,vjust=1) 

enter image description here


I agree that this is not entirely obvious, but not something that is also observed - in the help ?scale_size there is an example of using scale_area .

+7
source

All Articles