Search code examples
rggplot2geom-barfacet-grid

R geom_bar facet_grid vertical instead of horizontal


I am trying to make the same image I have but instead of horizontal each "propuesta", I want them to be in vertical. First "Propuesta A", under it "Propuesta B", and under this last one, "Propuesta C", as if each one of them is a separate graph, but together. I have the following code and output:

ggplot(articles_europaoccidental_sex_count_unique_group, aes(Country, percentage, fill = Gender)) + 
+     geom_bar(stat = "identity", position = "dodge") + 
+     facet_grid(~Propuesta) + geom_text(aes(label = round(percentage, 2)), position = position_dodge(width = 0.9), vjust = -1)

enter image description here Thanks!


Solution

  • As Richard Telford said, with a minimum change in my code it would work.

    The new code is

    ggplot(articles_europaoccidental_sex_count_unique_group, aes(Country, percentage, fill = Gender)) + 
      geom_bar(stat = "identity", position = "dodge") + 
      facet_wrap(~Propuesta, ncol = 1)
    

    enter image description here

    The only change was facet_grid(~Propuesta) to facet_wrap(~Propuesta, ncol = 1)