Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to move x labels to be over facet labels in ggplot in R

I would like to move the facet labels (3, 4, 5) to underneath the x values (4, 6, 8). My current code:

library(ggplot2)
ggplot(mtcars) + aes(factor(cyl), wt) + 
geom_bar(stat = "summary", fun.y = "mean") + 
facet_grid(~gear, switch = "x")

currently, it looks like this:

currently

I'm looking for something that looks like this:

goal

like image 627
Amit Sasson Avatar asked Dec 06 '17 15:12

Amit Sasson


Video Answer


1 Answers

library(ggplot2)
ggplot(mtcars) + aes(factor(cyl), wt) + 
geom_bar(stat = "summary", fun.y = "mean") + 
facet_grid(~gear, switch = "x") +
theme(strip.placement = "outside")

enter image description here

like image 65
Marco Sandri Avatar answered Sep 22 '22 01:09

Marco Sandri