作者:咔西咔嘻 | 来源:互联网 | 2024-09-29 10:40
Iamtryingtomakeascatterplotinggplot2withasizemappingtoathirdvariableanddensity2dc
I am trying to make a scatterplot in ggplot2 with a size mapping to a third variable and density2d contours. It seems as if the legend is being confused by the inclusion of density2d contours.
我试图在ggplot2中制作一个散点图,其大小映射到第三个变量和density2d轮廓。似乎传说因包含density2d轮廓而感到困惑。
For example, the following code works:
例如,以下代码有效:
library('ggplot2')
set.seed(1)
x=rnorm(100); y=rnorm(100,sd=10); z=seq(1,10,length.out=100)
dd=data.frame(x=x,y=y,z=z)
ggplot(dd,aes(x,y,size=z))+geom_point()
But now, note the legend behaves unusually when I add in a call to stat_density2d()
. In particular, the plot legend shows blue blocks instead of black circles:
但现在,请注意当我添加对stat_density2d()的调用时,图例的行为异常。特别是,图例显示蓝色块而不是黑色圆圈:
ggplot(dd,aes(x,y,size=z))+geom_point()+stat_density2d()
1 个解决方案