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