如何在R ggplot boxplot中删除未使用的因素? [英] How to drop unused factors in faceted R ggplot boxplot?

查看:96
本文介绍了如何在R ggplot boxplot中删除未使用的因素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我用来制作一些箱型图的一些示例代码:

  stest < -  read.table(text =现场年份浓
南2001年5.3
南2001年4.67
南2001年4.98
南2002年5.76
南2002年5.93
北2001年4.64
北2001年6.32
北部2003年11.5
北部2003年6.3
北部2004年9.6
北部2004年56.11
北部2004年63.55
北部2004年61.35
北部2005年67.11
2006年北部39.17 $ b $北部北部43.51 $ b $北部北部2006 76.21 $ b北部b 2006 2006 158.89 $ b北部b北部2006 122.27
,标题= TRUE)

require(ggplot2)
ggplot(stest,aes(x = year,y = conc))+
geom_boxplot(horizo​​ntal = TRUE)+
facet_wrap(〜site,ncol = 1)+
coord_flip()+
scale_y_log10()

这:





我尝试了所有我能想到的但不能在南面中仅包含显示数据的年份(2001年和2002年)。是我想要做的事情吗?



这是一个链接(DEAD)以显示我想要实现的屏幕截图:

facet_wrap 使用 scales ='free.x'参数。但我怀疑你需要做更多的事情来获得你想要的情节。

您的初始 aes(x =因子(年),y = conc) > ggplot 呼叫。


Below is some example code I use to make some boxplots:

stest <- read.table(text="    site  year    conc
    south   2001    5.3
    south   2001    4.67
    south   2001    4.98
    south   2002    5.76
    south   2002    5.93
    north   2001    4.64
    north   2001    6.32
    north   2003    11.5
    north   2003    6.3
    north   2004    9.6
    north   2004    56.11
    north   2004    63.55
    north   2004    61.35
    north   2005    67.11
    north   2006    39.17
    north   2006    43.51
    north   2006    76.21
    north   2006    158.89
    north   2006    122.27
", header=TRUE)

require(ggplot2)
ggplot(stest, aes(x=year, y=conc)) +
  geom_boxplot(horizontal=TRUE) +
  facet_wrap(~site, ncol=1) +
  coord_flip() +
  scale_y_log10()

Which results in this:

I tried everything I could think of but cannot make a plot where the south facet only contains years where data is displayed (2001 and 2002). Is what I am trying to do possible?

Here is a link (DEAD) to the screenshot showing what I want to achieve:

解决方案

Use the scales='free.x' argument to facet_wrap. But I suspect you'll need to do more than that to get the plot you're looking for.

Specifically aes(x=factor(year), y=conc) in your initial ggplot call.

这篇关于如何在R ggplot boxplot中删除未使用的因素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆