当前位置: 动力学知识库 > 问答 > 编程问答 >

r - Use density to set color and size of points using ggplot

问题描述:

I just want to set the color and size of the point.

I've found quite a few posts but nothing I was able to reverse engineer.

Is it possible?

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)))

Edit: I think I got it, but now my question becomes is what I did correct or a hack? New code:

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))))

网友答案:

This produces a plot without error on my device:

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

If you need something different you should make clear what such differences might be

分享给朋友:
您可能感兴趣的文章:
随机阅读: