简体   繁体   English

更改图例中标度的缩放比例以指示点的值

[英]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. 许多样本的大小从10到50,其他样本则基于500或1000个测量值。

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. 我想更改图例,以指示样本大小10和50以及500和1000的点大小。

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 . 绝对不应在aes内使用$ -indexing。 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. 您应该始终提供可重现的最小样本,以便SO被调查者可以使用。 Explicit sample data also often helps avoid ambiguities regarding data types. 显式样本数据通常还有助于避免有关数据类型的歧义。

As to your question, you can use scale_size_continuous . 关于您的问题,您可以使用scale_size_continuous Here is a reproducible example based on mtcars 这是基于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. 请注意, scale_size缩放点的面积,而scale_radius缩放半径。 An alternative to scale_size is scale_size_area which ensures that a value of 0 is mapped to a size of 0. scale_sizescale_size_area的替代方法,可确保将值0映射到大小0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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