我想使用类似方面的方式比较数据bar plot,但缺少数据会导致条形“宽度”不同:
我怎么能够
- 确保相同的条形尺寸(“宽度”)和
- [很好]将每个面的面板尺寸缩小到真正需要的尺寸?
PS:我不想将空数据显示为“零栏”,以免浪费空间。
library(ggplot2)
data <- data.frame(product = c("Fish", "Chips", "Baguette"),
store = c("London", "London", "Paris"),
customer.satisfaction = c(0.9, 0.95, 0.8),
stringsAsFactors = TRUE)
data
ggplot(data, aes(x = product, y = customer.satisfaction)) +
geom_bar(stat = "identity", width = 0.9) +
coord_flip() +
facet_wrap( ~ store, ncol = 1, scales = "free_y")
也许使用面网格的方法会令人满意:
ggplot(df, aes(x = product, y = customer.satisfaction)) +
geom_bar(stat = "identity", width = 0.9) +
coord_flip() +
facet_grid(store ~., scales = "free", space = "free")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)