这是来自“R for Data Science”的数据可视化问题。
问题5.在我们的比例条形图中,我们需要设置group = 1,为什么?换句话说,这两张图有什么问题?
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, y = ..prop..))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = color, y = ..prop..))
Run Code Online (Sandbox Code Playgroud)
正如您看到的代码及其结果,y-axix 中存在一个问题,因为不包括 group 参数。我很清楚,所以在将原始代码更改为下面之后。
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = color, y = ..prop.., group = 1))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, …Run Code Online (Sandbox Code Playgroud)