This is a continuation of this question: Labeling facet strips in ggplot2
By using the following code, I can obtain Year = 2009, Year = 2010 to the top of each sub plot:
set.seed(1)
df=data.frame(year=rep(2009:2013,each=4),
quarter=rep(c("Q1","Q2","Q3","Q4"),5),
sales=40:59+rnorm(20,sd=5))
library(ggplot2)
ggplot(df) +
geom_line(aes(x=quarter,y=sales,group=year))+
facet_wrap(
.~year,
labeller = as_labeller(\(x) paste0("Year=", x)),
strip.position = "top",
scales = "free") +
theme(#panel.spacing = unit(0, "lines"),
strip.placement = "outside",
axis.title.x=element_blank(),
legend.position="none")
How should I modify the aforementioned code if I need to have a subscript, let's say for example, instead of Year = 2009, I need to display Year ab = 2009
I tried giving
... +
facet_wrap(
.~year,
labeller = as_labeller(\(x) paste0("Year", bquote(a[b]) ,"=", x)),
strip.position = "top",
scales = "free"
) +
...
but it failed.