在一个小格两个图形力X轴时,X值是相同的(Force X axis on both graphs i

2019-06-25 06:12发布

我有大约30类别两组为刻面X轴数据。 我会用一些随机的数据显示如下:

dataf <- data.frame(x=c(1:30), A=rnorm(30,20,5), B=rnorm(30,15,0.5))
datam <- melt(dataf, id="x")
ggplot(datam, aes(factor(x), value)) + 
  geom_bar(stat="identity") + 
  facet_grid(variable ~ .)

这仅仅是可爱的,但它会更容易些,如果x轴是对图形再现太顶部分组,快速读出的类别。 然而

ggplot(datam, aes(factor(x), value)) + 
  geom_bar(stat="identity") + 
  facet_grid(variable ~ ., scales="free")

使得x轴,因为,我想,值是两个集团同样没有什么区别。

我如何可以强制将被再现的顶级组以及酒吧的X轴?

Answer 1:

尝试使用facet_wrap代替:

ggplot(datam, aes(factor(x), value)) + 
    geom_bar(stat="identity") + 
    facet_wrap(~variable,nrow = 2,scales = "free")



文章来源: Force X axis on both graphs in a facet grid when X values are the same