我在GGPLOT2使這個點陣圖:如何使平滑密度適合ggplot2的dotplots?
ggplot(mtcars, aes(x = mpg)) + geom_dotplot()
我想表明某種平滑密度適合在散點圖頂部的觀察點。這看起來不正確:
ggplot(mtcars, aes(x = mpg)) + geom_dotplot() + geom_density()
我試圖stat_smooth()
但我得到的錯誤:
> ggplot(mtcars, aes(x = mpg)) + geom_dotplot() + stat_smooth()
stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error: stat_smooth requires the following missing aesthetics: y
感謝。
什麼看起來不正確?你意識到密度估計不會與分箱計數的規模相同,對吧? – joran 2013-04-25 21:38:45
@joran:正好。這就是爲什麼我需要一些適合內核密度的東西來適應實際的點堆,所以它們的尺寸大致相同 – user248237dfsf 2013-04-26 00:08:25
實際上,我認爲它僅僅適合一個合適的內核密度估計值,這只是因爲你不喜歡結果。看看我的意思,嘗試使用'geom_density(adjust = 0.5)'。這裏沒有真正的「正確」,你只需要修改bin寬度和kde參數,直到你找到一些看起來令人愉悅的東西。 – joran 2013-04-26 01:31:43