'Separate lines in facet_grid labels

Is there a way to print the text shown in the facet_grid label on separate lines? In the example below I would like to "Test" to be printed above "Group". I have been trying using ggtext, but I don't get it to work. Does anyone know of some way to do it?

library(tidyverse)
library(ggtext)

df <- tibble(X = c("A","A","B","B","C","C","B","B","B","C","C"),
             value = c(5,2,7,3,1,6,9,4,2,5,2),
             type = c("t","t","t","t","t","s","s","s","s","s", "s"),
             group = c("T1G1","T2G2","T1G1","T2G2","T1G1","T1G1","T3G3","T2G2","T3G3","T3G3", "T3G3"))

re_names <- c(
  "T1G1" = "Test1<b>Group1",
  "T2G2" = "Test2<b>Group2",
  "T3G3" = "Test3<b>Group3")

df %>% ggplot(aes(X,value)) +
  geom_col(aes(fill=type)) +
  facet_grid(~group,
             labeller = as_labeller(re_names))

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source