2015-07-20 19 views
-1

我只是想設置點的顏色和大小。 我發現不少帖子,但沒有任何我能夠逆向工程。 這可能嗎?使用密度來設置顏色和點的大小使用ggplot

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

回答

2

這是我的設備上產生一個描無誤:

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

如果你需要不同的東西,你應該清楚是什麼這種差異可能是enter image description here

相關問題