4

I have two geoms in a ggplot2 object that both use the size aesthetic. How can I manually supply the size range to one geom but exclude the others?

So in the plot below I want to do scale_size for the geom_point but exclude geom_text's size aesthetic.

library(ggplot2)

mtcars$car <- rownames(mtcars)

ggplot(mtcars, aes(mpg, wt)) +
    geom_point(aes(size=disp), alpha=.2) +
    geom_text(aes(label=car, size=disp)) +
    scale_size(range=c(11, 20))
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
  • 1
    do you need to map size in geom_text? `geom_text(aes(label=car), size=as.numeric(cut(mtcars$disp, breaks = 4)))` what do you want the figure to look like – rawr Mar 30 '16 at 21:17
  • 2
    `annotate("text",x = mtcars$mpg,y = mtcars$wt,label = mtcars$car,size = 0.01 * mtcars$disp)` also seems to generate what I think you're after, but I'm not sure. – joran Mar 30 '16 at 21:19
  • 2 more solutions? http://stackoverflow.com/a/35213634/4718512 – oshun Mar 30 '16 at 21:21

0 Answers0