this may be a very niche question but I’m looking for a way to automatically insert title names for rows of labels.
I look at a lot of multifactorial data for drug to drug interactions, and one nice format to save space is to use – and + symbols in rows on the x-axis as titles in order to show which drugs / factors are present, and then have a title for each row of -/+ symbols to indicate the corresponding factor. Where I am struggling with is some precise / less hack-ish way of inserting this?
Below is an example of what I mean – I’ve just manually pasted in the titles here (highlighted in red) in powerpoint but it would be great if there was a more precise way of doing this! Thanks in advance for any advice.
df <- data.frame(drug_a = rep(c("untreated", "untreated", "treated", "treated"), 4),
drug_b = rep(c("untreated", "treated", "untreated", "treated"), 4),
group = rep(c("a", "b", "c", "d"), 4),
condition_a = c(rep(c("w"), 8), rep(c("x"), 8)),
condition_b = c(rep(c("y"), 4), rep(c("z"), 4), rep(c("y"), 4), rep(c("z"), 4)),
reading = c(1:16))
plusminus.labels <- c("-n-", "-n+", "+n-", "+n+")
names(plusminus.labels) <- c("a", "b", "c", "d")
ggplot(df, aes(x=group, y=reading)) +
geom_bar(position = "dodge", stat = "identity")+
facet_grid(condition_a~condition_b) +
scale_x_discrete(labels = plusminus.labels)