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

时间:2013-09-09 12:46:20

标签: r ggplot2 facets

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

我有gtplot2的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)

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

anomalies' trends by VEG

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

由于

1 个答案:

答案 0 :(得分: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)

显然,如果没有您的数据,我无法确定这会给您什么,但根据您的描述,它应该有效。我发现使用ggplot,通常最好将它传递给你想要绘制的数据,而不是找到改变绘图本身的方法。