我试图找出一种巧妙的方法来从ggplot2中的facet中删除未使用的因子.这是一个最小的例子
# DUMMY DATA
mydf = data.frame(
x = rpois(6, 25),
y = LETTERS[1:6],
cat = c(rep('AA', 3), rep('BB', 3)))
# PLOT IT!
p0 = ggplot(mydf, aes(x = x, y = y)) +
geom_point() +
facet_wrap(~ cat, ncol = 1)
Run Code Online (Sandbox Code Playgroud)
从下图可以看出,尽管事实上没有相应的数据,但因子D,E和F都是在方面AA中绘制的.我想要的是从方面AA中消除{D,E,F}的方法以及从方面BB中类似地{A,B,C}.
有没有一个巧妙的方法来做到这一点,甚至一个黑客是可以接受的.

jor*_*ran 11
我认为你所需要的只是scales = "free_y":
p0 = ggplot(mydf, aes(x = x, y = y)) +
geom_point() +
facet_wrap(~ cat, ncol = 1,scales = "free_y")
p0
Run Code Online (Sandbox Code Playgroud)
