Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to have x-axis labels in multicolumn ggplot with facet_wrap?

Tags:

r

ggplot2

When trying to plot something like this:

library(ggplot2)
d <- ggplot(diamonds, aes(carat, price)) +
  xlim(0, 2) + geom_point()
d + facet_wrap(~ color)

You will notice that the x-axis labels only show up for the first column. I would like them to repeate on the second and third column. Is this possible?

If on the facet_wrap I use the option scales="free",

d + facet_wrap(~ color, scales="free")

then i get x-axis labels on all plots, which I also don't want. I want only labels in the bottom row repeating across columns

If the number of panels to be plot is such, that all columns have the same number of plots, the axis gets repeated in the way I want. But I can't always have the right number of panels for that.

like image 701
zelite Avatar asked May 14 '13 08:05

zelite


People also ask

How do I change X label to R in Ggplot?

To alter the labels on the axis, add the code +labs(y= "y axis name", x = "x axis name") to your line of basic ggplot code. Note: You can also use +labs(title = "Title") which is equivalent to ggtitle .

How to remove facet_ wrap labels in ggplot?

Set the strip. text element in theme() to element_blank() . Setting strip. text to element_blank() will remove all facet labels.

What is XLAB and YLAB?

xlab="x-axis label", ylab="y-axis label") Many other graphical parameters (such as text size, font, rotation, and color) can also be specified in the title( ) function.


1 Answers

With version 2.2.0 of ggplot this problem is fixed. see https://www.rstats-tips.net/2016/11/ggplot2-x-axis-scale-now-available-on-all-facet-columns/

enter image description here

like image 134
JerryWho Avatar answered Nov 14 '22 23:11

JerryWho