[英]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: 两条一般性评论:
$
-indexing inside aes
. 您绝对不应在aes
内使用$
-indexing。 See this post to understand what can go wrong if you do. 请参阅这篇文章,以了解如果这样做会出错。 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_size
是scale_size_area
的替代方法,可确保将值0映射到大小0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.