使用密度使用ggplot设置点的颜色和大小

时间:2015-07-20 23:38:53

标签: r ggplot2

我只想设置点的颜色和大小。 我发现了不少帖子,但我没有能够进行逆向工程。 有可能吗?

require(ggplot2)
d <- ggplot(diamonds, aes(price)) #+ xlim(0, 3)
d + stat_bin(aes(size = ..density.., color=..density..),
             binwidth = 0.1,geom = "point",
             position="jitter")  +
     guides(col = guide_legend(override.aes = list(shape = 15, size = 10)))

编辑:我想我明白了,但现在我的问题变成了我做的正确还是黑客?新代码:

require(ggplot2)
d <- ggplot(diamonds, aes(price)) #+ xlim(0, 3)
d + stat_bin(aes(size = ..density.., color=..density..),
             binwidth = 0.1,geom = "point",
             position="jitter")  +
    guides(col = guide_legend(override.aes = list(shape = c(16,16,16,16,16),
                                                  size = c(2,3,4,5,6))))

1 个答案:

答案 0 :(得分:2)

这会在我的设备上产生无错误的情节:

d + stat_bin(aes(size = ..density.., color= ..density..), 
             binwidth = 0.1,geom = "point", position="jitter") 

如果您需要不同的东西,您应该明确这些差异可能是enter image description here