ggplot:如何从一个方面删除未使用的因子水平?

ggplot: how to remove unused factor levels from a facet?

代码如下

d1 = data.frame(y=1:2,group=factor(c('A','B'), levels=c('A','B','C')), fac = 'f1')
d2 = data.frame(y=1:3,group=factor(c('A','B','C'), levels=c('A','B','C')), fac = 'f2')
d = rbind(d1,d2)

library(ggplot2)
ggplot( d, aes(x=group, y=y) ) + geom_point(size=3) + facet_grid( ~ fac)

结果如下图。如何从方面 'f1' 中删除未使用的因子水平 C

在小平面网格中设置 scales = free 就可以了:

facet_grid( ~ fac, scales = "free")