1
分組我目前正在讀R for Data Science
並試圖創造一些圖表。我知道要在條形圖中獲得比例,您需要使用group = 1
。例如,下面的代碼工作:繪圖比例另一個變量
library(ggplot2)
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, fill = color))
但我沒有得到相同的比例圖。
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, fill = color, y = ..prop.., group = 1))
我確實得到了比例,但不是color
。
你不需要'tidyverse'軟件包這一 –
'diamonds'是ggplot2'的'一部分,你唯一需要的包爲了這。 – Gregor