简体   繁体   中英

Change the scaling in the legend for the size of dots which indicates the value

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:

  1. You should never use $ -indexing inside aes . See this post to understand what can go wrong if you do.
  2. You should always provide reproducible minimal sample so that SO respondents have something to work with. Explicit sample data also often helps avoid ambiguities regarding data types.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM