0

I have the following dataset which produces a grouped bar plot:

library(ggplot2)
library(dplyr)
expand.grid(gender=c("M","F"), 
            education=c("HS","College","Advanced"), 
            value = sample(1:20,8, replace = T)) %>% 
  ggplot(aes(x =  education, y = value, fill = gender))+
  geom_col(position = position_dodge())

enter image description here

But instead of having a legend I want the labels to be on the x axis like this:

enter image description here

Is this possible?

Thanks

jmich738
  • 1,565
  • 3
  • 24
  • 41
  • 4
    Make education level the facetting variable and gender the x variable (optionally also the fill variable). Adjust the theme to put the facet labels at the bottom if that's where you want them. Similar to here https://stackoverflow.com/q/20571306/5325862 – camille Aug 06 '19 at 04:36

1 Answers1

0

as camille already mentioned in a comment, you can use facet_wrap

expand.grid(gender=c("M","F"), 
        education=c("HS","College","Advanced"), 
        value = sample(1:20,8, replace = T)) %>% 
ggplot(aes(x =  gender, y = value, fill = gender))+
geom_col(position = position_dodge()) +
facet_wrap(~education)

The resulting plot looks like this:

resulting plot

If you want to remove the legend, just add theme(legend.position="none")

jkrainer
  • 413
  • 5
  • 10