15
votes

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!

1
I'm afraid I don't understand what you mean. The two images look similar to me, apart from the axis labels. - Andrie
Right. The user wants to change the positioning of the axis labels in the 4th column (or remove them). - IRTFM
@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
@user1535384: Can you please provide the code for your plot? - naught101

1 Answers

2
votes

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