Why this facet_grid doesn't delete columns?

泄露秘密 提交于 2019-12-01 20:21:07

You get all levels shown on plot because all levels are used. Levels are dropped if they are not used at all. To remove levels in each facet add scale="free_x" to facet_grid(). But this will not work in particular case because you use different statements of x values in ggplot() and stat_summary() calls. I would suggest to add new column before plotting with interaction.

tdat$int<-with(tdat,interaction(Condition,variable,drop=TRUE,sep='-'))
ggplot(tdat,aes(int,value,fill=Condition))+
  stat_summary(fun.y='mean', geom='bar')+
  geom_point()+
  facet_grid(.~variable,scales="free_x")

In this case you can simplify your code without interaction() because you use also facet_grid().

ggplot(tdat,aes(Condition,value,fill=Condition))+
  stat_summary(fun.y='mean', geom='bar')+
  geom_point()+
  facet_grid(.~variable)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!