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.
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 .
Set the strip. text element in theme() to element_blank() . Setting strip. text to element_blank() will remove all facet labels.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With