R 具有面和相同条尺寸(binwidth)的条形图,可选择缩小面板尺寸
我希望使用条形图以类似方面的方式比较数据,但缺少数据会导致条形宽度不同: 我怎么能 确保钢筋尺寸和宽度相同 [很高兴拥有]将每个面的面板大小缩小到真正需要的大小? PS:我不想将空数据显示为零条,以免浪费空间R 具有面和相同条尺寸(binwidth)的条形图,可选择缩小面板尺寸,r,ggplot2,R,Ggplot2,我希望使用条形图以类似方面的方式比较数据,但缺少数据会导致条形宽度不同: 我怎么能 确保钢筋尺寸和宽度相同 [很高兴拥有]将每个面的面板大小缩小到真正需要的大小? PS:我不想将空数据显示为零条,以免浪费空间 library(ggplot2) data <- data.frame(product = c("Fish", "Chips", "Baguette"), store = c("London", "London", "Paris"),
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")
好成绩!我唯一的观点是,应该在绘图顶部显示刻面标签,因为刻面网格不支持IMHO,因为刻面包裹使用strip position参数。知道吗?@R尤达我不知道ggplot2中有这个功能。如前所述,通过操纵grob可以实现所需的行为