Using ggplot to plot proportional area symbols 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)
As you can see the labels are rooted when I need them to show the original data. Have tried playing with the scale_size options but nothing works. Anyone know a fix to this, or is there maybe an obscure setting to achieve proportional area size mapping?
Thanks in advance.
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)
I agree, it's not entirely obvious, but not that obsure either - there is an example using scale_area
in the help for ?scale_size
.
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