垂直和水平条形图

ggplot(data = diamonds, aes(x = cut, fill =color)) +
  geom_bar(stat = "count", position = "dodge")

StackOverflow 文档

只需在 ggplot 对象中添加 coord_flip() 美学,就可以获得水平条形图:

  ggplot(data = diamonds, aes(x = cut, fill =color)) +
  geom_bar(stat = "count", position = "dodge")+
  coord_flip()

StackOverflow 文档