垂直和水平條形圖

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 文件