I am setting up a scatter plot, and the size of the dots represents the number of samples the measurement was based.
There is a skewed distribution of the samples sizes for the values / dots.
Many have samples sizes from 10 to 50 and others are based on 500 or 1000 measurements.
I would like to change the legend in a way that the dot size for sample size 10 and 50 as well as 500 and 1000 is indicated.
Which setting would allow this?
gg.pf0<-ggplot(bc.pf,aes(x=age.WERT,y=weight,color=as.factor(bc.pf$Group),size=(bc.pf$n)))
(gg.pf1<-gg.pf0 + geom_point(aes(alpha=0.5)))
Two general comments:
$
-indexing inside aes
. See this post to understand what can go wrong if you do. As to your question, you can use scale_size_continuous
. Here is a reproducible example based on mtcars
ggplot(mtcars, aes(mpg, disp, size = hp)) +
geom_point() +
scale_size_continuous(
breaks = c(10, 50, 500, 1000),
limits = c(0, 1000))
Note that scale_size
scales the area of the dots, while scale_radius
scales the radius. An alternative to scale_size
is scale_size_area
which ensures that a value of 0 is mapped to a size of 0.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.