This is a variant of this question and this question that I haven't found a solution to.
Using mtcars as an example I want a plot similar to the following
ggplot(mtcars, aes(x=cyl,y=mpg)) +
geom_point() +
facet_grid(am ~ gear + carb)
However, I want the facet x labels associated with the "carb" variable to be removed while keeping the label for the "gear" variable. The following gets at what I want, but puts "NA" in it's place rather than completely removing it.
ggplot(mtcars, aes(x=cyl,y=mpg)) +
geom_point() +
facet_grid(am ~ gear + carb, labeller = labeller(carb = "")
Of course, using theme(strip.text.x = element_blank()) doesn't work for me either since I want to keep the label for the "gear" variable.
Ultimately, I want to grid using both x layers but for me the label for the second x layer doesn't hold any meaning so it's distracting to include in the plot.
For reasons I also don't understand, the following seems to work. The function just returns a vector of empty strings of equal length as the input.
library(ggplot2)
ggplot(mtcars, aes(x=cyl,y=mpg)) +
geom_point() +
facet_grid(am ~ gear + carb,
labeller = labeller(carb = function(x) {rep("", length(x))}))

Created on 2021-01-12 by the reprex package (v0.3.0)
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