只选择一些要在facet_wrap,ggplot2中打印的构面

use*_*133 2 r ggplot2 facets

我的问题很简单,但经过多次尝试后我都未能解决.我只想打印一个刻面图(使用ggplot2中的facet_wrap制作)的一些方面,并删除我不感兴趣的那些.

我有与ggplot2的facet_wrap,如下所示:

#anomalies linear trends
an.trends <- ggplot()+
  geom_smooth(method="lm", data=tndvilong.anomalies, aes(x=year, y=NDVIan, colour=TenureZone,
                                                     group=TenureZone))+
  scale_color_manual(values=miscol) + 
  ggtitle("anomalies' trends")

#anomalies linear trends by VEG
an.trendsVEG <- an.trends + facet_wrap(~VEG,ncol=2)
print(an.trendsVEG)
Run Code Online (Sandbox Code Playgroud)

我按照预期得到了情节(你可以在下面的te链接中看到它):

VEG的异常趋势

问题是:我如何只打印出我感兴趣的面孔?我只想打印"CenKal_ShWoodl","HlShl_ShDens","NKal_ShWoodl"和"ThShl_ShDens"

谢谢

ale*_*han 5

我建议最简单的方法是简单地给出ggplot()一个合适的子集.在这种情况下:

facets <- c("CenKal_ShWoodl", "HlShl_ShDens", "NKal_ShWoodl", "ThShl_ShDens")
an.trends.sub <- ggplot(tndvilong.anomalies[tndvilong.anomalies$VEG %in% facets,])+
  geom_smooth(method="lm" aes(x=year, y=NDVIan, colour=TenureZone,
                                                     group=TenureZone))+
  scale_color_manual(values=miscol) + 
  ggtitle("anomalies' trends") +
  facet_wrap(~VEG,ncol=2)
Run Code Online (Sandbox Code Playgroud)

显然没有你的数据,我不能确定这会给你你想要的东西,但根据你的描述,它应该工作.我发现使用ggplot,通常最好将它想要绘制的数据传递给它,而不是找到改变绘图本身的方法.