15

Using facet_wrap in ggplot2 to create a grid, but I have an uneven number of panels so the last row is incomplete. At the bottom of the last, blank panel is the axis ticks and text. Is it possible to shift this axis up (giving the last facet in each column the appearance of having applied free_x)? If not, can I remove it altogether as is seen below?

To clarify with examples, this is what I'm getting: http://sape.inf.usi.ch/sites/default/files/ggplot2-facet-wrap.png

enter image description here

I desire something seen here (though, ideally with axis labelling on the facet in column 4): Changing facet label to math formula in ggplot2

enter image description here

Thanks for any ideas or insight!

Community
  • 1
  • 1
user1535384
  • 151
  • 1
  • 3
  • I'm afraid I don't understand what you mean. The two images look similar to me, apart from the axis labels. – Andrie Aug 23 '12 at 17:42
  • 2
    Right. The user wants to change the positioning of the axis labels in the 4th column (or remove them). – IRTFM Aug 23 '12 at 17:51
  • 5
    @DWin Got it - keep the axis labels in the fourth column , but move them vertically. I doubt that's going to be possible without doing it manually in `grid`. – Andrie Aug 23 '12 at 18:02
  • @user1535384: Can you please provide the code for your plot? – naught101 Oct 09 '12 at 06:36

1 Answers1

2

Using facet_wrap, when I do this in 0.9.1, ggplot hides the x-axes on the columns with blanks, as shown below.

movies$decade <- round(movies$year, -1)
ggplot(movies) + geom_histogram(aes(x=rating)) + facet_wrap(~ decade, ncol=5)

enter image description here

Christian
  • 1,499
  • 2
  • 12
  • 28
  • 1
    There may be some version differences happening here: the original question is a few months old. With ggplot 0.9.2.1 and a made-up example (8 facets in a 3x3 wrapped array), I don't get the extra set of axis labels, whether or not I specify the number of columns. In your example I have to use `ncol=5` to force an uneven array size (otherwise I get a 3x4 array), or delete the 2000s, but if I do the latter I still get the blank axes as appropriate. – Ben Bolker Oct 11 '12 at 21:04
  • Confirmed, manual specification doesn't matter. I'm rewording the answer. – Christian Oct 11 '12 at 21:35