3

In ggplot2 3.1.0, I'm confused about how scale_size_continuous works. The help documentation seems to suggest that the size scale is controlling point area, with trans="identity". Yet it's clear this isn't what's happening.

library(tidyverse)

#make data
plotdat<-data.frame(x=runif(6), y=runif(6), size=seq(10,60,10))

#simple plot
plotdat %>% ggplot(aes(x, y, size=size))+
geom_point()+
scale_size_continuous()

not scaling the way I expect

#but help file seems to indicate that scale_size scales point area 
?scale_size_continuous

There is a note in the documentation that scale_size_area ensures that when size==0, the point will have 0 area. If I use this, then it appears that the point area increases linearly with size.

#simple plot
plotdat %>% ggplot(aes(x, y, size=size))+
geom_point()+
scale_size_area()

is scaling the way I'd expect

What is actually happening with scale_size_continuous-- how does it translate the size argument to point area?

EDIT after several comments I have a suspicion: perhaps both scale_size_continuous and scale_size_area increase linearly with size, but have different intercepts. Thus the fact that the point associated with size 20 in the first plot is way more than double the area of the point with size 10 is ok, because approximately the same number of pixels are added between 10 and 20 as between 20 and 30 or 40 and 50.

This is not the behavior I would expect when using, e.g. point size to indicate the number of individuals, but is consistent with area increasing linearly with size, within range.

Michael Roswell
  • 1,300
  • 12
  • 31
  • 2
    The sizes are changing. How do you know it isn't scaling linearly? Are you measuring the area with some other tool? – IceCreamToucan Jan 16 '19 at 15:23
  • Related: https://stackoverflow.com/questions/11570821/changing-the-range-of-sizes-used-in-a-bubble-plot I think it's linear, as you can see from the source code. Couldn't find documentation. **EDIT** Maybe not as a comment on this post recommends changing the range until it looks right! – NelsonGon Jan 16 '19 at 15:28
  • Hmm. I just measured again with a ruler. On my screen, the diameter point associated with size 10 is about 1mm, 20 about 3 mm, 30 about 4mm, 60 looks just shy of 5 mm. – Michael Roswell Jan 16 '19 at 15:33
  • @Michael, would it work for your needs to use `geom_circle` instead of `geom_point`, and map `r` to the square root of the desired area? – A. S. K. Jan 16 '19 at 17:09
  • It works fine for my purpose to simply use `geom_point` and `scale_size_area`. But I'd love to know why `scale_size_continuous` doesn't also work this way and what it's doing instead. Great suggestion though! – Michael Roswell Jan 16 '19 at 17:22
  • 1
    If you want size to scale linearly with the diameter / radius, use `scale_radius` instead. – Z.Lin Jan 18 '19 at 10:07

0 Answers0