Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove "floating" axis labels in facet_wrap plot?

Tags:

r

ggplot2

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!

like image 373
user1535384 Avatar asked Aug 23 '12 16:08

user1535384


1 Answers

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

like image 104
Christian Avatar answered Oct 04 '22 12:10

Christian