Determine size of circles in the legend of a GGPLOT2 chart

2

Hello

I inserted these commands there in the R:

library(ggplot2)
lm_smooth <- geom_smooth(method = lm, size = 1)
qplot(percwhite, percbelowpoverty, data = midwest,
weight = popdensity, size = popdensity) + lm_smooth

And R returned this chart to me:

Would anyone tell me how I can determine the values that appear in the caption? For example: instead of 4 sizes of different circles, I would like to determine how many I wanted.

    
asked by anonymous 12.08.2018 / 07:44

1 answer

4

You can use scale_size () to define the sizes.

qplot(x = percwhite, y = percbelowpoverty, data = midwest,
      size = popdensity) + 
      scale_size(range = c(1,4),
             breaks = c(10000, 20000, 30000, 40000, 50000, 60000, 70000),
             labels = c("10000","20000","30000", "40000", "50000","60000", "70000"),
             guide = "legend") +
      lm_smooth

    
12.08.2018 / 19:47