What does the height of bars in the two bar chats with different “position” represents?

假如想象 提交于 2021-01-28 11:52:54

问题


I know in this command line the height of the bars represents the count of each group in this variable "color":

ggplot(diamonds, aes(color, fill = cut)) +
  geom_bar()

But I really wanna know what about this command line:

ggplot(diamonds, aes(color, fill = cut)) +
  geom_bar(alpha=0.5, position = "identity")

I know the former is defaulted as position "stack" and I also know the meaning of position "identity". But I really can't figure out what the height of the bars in the later one represents?

Thanks many in advance!


回答1:


I think the best way to understand it is to imagine using position='dodge' (which places multiple bars for different cuts, separated by color) and instead layering all the cut bars on top of each other.

ggplot(diamonds, aes(color, fill = cut)) +
  geom_bar(alpha=0.5, position = "dodge")

ggplot(diamonds, aes(color, fill = cut)) +
  geom_bar(alpha=0.5, position = "identity")

(Note, the colors get distorted because the 'Fair' cut is in front.)




回答2:


When you use position=stack, for each x position counts per group in the fill are.stacked on top.of each other..with position=identity on the other hand for each x position if there are multiple groups in the fill varaibles they also start at y=0 and are essentially overlaid.



来源:https://stackoverflow.com/questions/60843077/what-does-the-height-of-bars-in-the-two-bar-chats-with-different-position-repr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!