I have some crossed multi-level data that I'd like to plot using facet_grid. The basic plot is something like the following:
library(tidyverse)
df <- expand_grid(g1 = c('AAAAAAAAAAAAAAAA', 'BBBBBBBB', 'CCCCCCCCC', 'DDDDDDDDD'),
g2 = c('e', 'f', 'g', 'h'),
g3 = c('I', 'J', 'K', 'L'),
x = 1:50) %>%
mutate(
x = rnorm(3200) # just replace with some random values
)
ggplot(data = df, aes(y = g2, x = x, color = g1)) +
stat_summary() +
facet_grid(cols = vars(g3), rows = vars(g1), switch = "y") +
theme_classic() +
theme(
strip.placement = "outside", # Place facet labels outside x axis labels.
strip.background = element_blank(), # Make facet label background white.
legend.position = "none",
strip.text.y = element_text(angle = 0)
)
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`
Created on 2021-05-07 by the reprex package (v2.0.0)
However, the main problem is that some of the "g1" labels are too long to be displayed (e.g. the "AAAA..." in this example). Therefore I'd like to rotate the strip text so it's horizontal and displays the whole thing. However, the strip.text.y = element_text(angle = 0)
doesn't seem to be doing anything here. Is there anything else I can try? Or perhaps there is a better way to handle this issue? Thanks so much for your help!