仅绘制facet_grid中选择的几个面

use*_*1_G 6 r ggplot2

我一直在寻找一种方式使用绘制facet_gridggplot2,只有显示器短短选择方面.说我有以下情节:

在此输入图像描述

一直在寻找一种快速方法,例如,只绘制方面1和3.

#data
y<-1:12
x<-c(1,2,3,1,2,3,1,2,3,1,2,3)
z<-c("a","a","a","b","b","b","a","a","a","b","b","b")
df<-as.data.frame(cbind(x,y,z))

#plot

a <- ggplot(df, aes(x = z, y = y,
  fill = z))
b <- a + geom_bar(stat = "identity", position = "dodge")
c <- b + facet_grid(. ~ x, scale = "free_y")
c
Run Code Online (Sandbox Code Playgroud)

显然我想出了如何首先删除我的数据,但这当然可以分配,ggplot2即使只是轻推也是最受欢迎的.

bde*_*est 10

subsetggplot通话中使用.

plot_1 = ggplot(subset(df, x %in% c(1, 2)), aes(x=z, y=y, fill=z)) +
         geom_bar(stat = "identity", position = "dodge") +
         facet_grid(. ~ x, scale = "free_y")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述