0

I have repeated facet headers that I need to combine into a single header with the following sample data:

    structure(list(Level1 = structure(c(1L, 1L, 1L, 1L, 1L), .Label = 
    "Repeated", class = "factor"), Level2 = structure(c(1L, 1L, 2L, 2L, 2L), 
    .Label = c("A", "B"), class = "factor"), Level3 = structure(1:5, .Label 
    = c("A", "B", "C", "D", "E"), class = "factor"), Value = c(6L, 2L, 3L, 
    4L, 0L)), .Names = c("Level1", "Level2", "Level3", "Value"), class = 
    "data.frame", row.names = c(NA, -5L))

I created a barplot with ggplot2 using facet_wrap() and set the number of columns to 1:

    ggplot(data=samp, aes(x=reorder(Level3, Value), y=Value)) +
    geom_bar(stat="identity") +  
    coord_flip() +
    ylab("Value") +
    xlab("Level3") +
    facet_wrap(~Level1 + Level2, scales = 'free_y', ncol = 1)

I need to show the nesting for the Level3, Level2, and Level1 factors but without repeating any facet headers. Here the Level1 factor facet header is repeated.

I attempted to follow instructions from the post below, but could not figure out how to customize to my data: Nested facets in ggplot2 spanning groups

Any assistance is appreciated.

user3594490
  • 1,949
  • 2
  • 20
  • 26
  • I don't totally understand the output you are trying achieve. If you remove `Level1` from `facet_wrap`, is that the plot you are looking for? – smanski Mar 26 '18 at 19:32
  • Since all your Level1 values are identical, why bother faceting based on it? For example `facet_wrap(~Level2, scales = 'free_y', ncol = 1)` seems to do what you want. – MrFlick Mar 26 '18 at 19:33
  • I wanted to provide the simplest data sample possible. I have multiple Level1 names in a larger data set, so I can not exclude that factor. I would like to know how to avoid the Level1 repeats when there are multiple nested Level2's. Thanks. – user3594490 Mar 26 '18 at 19:43
  • I'm not entirely sure what you need, but would `facet_grid` work? Such as `facet_grid(Level1 ~ Level2, scales = "free_y")`. Won't give you access to the single column layout, but it would show the combination of factors for each facet. – camille Mar 26 '18 at 20:40
  • @Camille I think that is a workable option. Many thanks. – user3594490 Mar 26 '18 at 21:15

0 Answers0