I have the following plot:
I would like to add another level on the x-axis so it looks something like this:
Here is my data:
results <- dput(results)
structure(list(tdcs = c("active", "active", "active", "active",
"active", "active", "sham", "sham", "sham", "sham", "sham", "sham"
), type = c("Trained Words", "Trained Words", "Untrained Words",
"Untrained Words", "Comprehension", "Comprehension", "Trained Words",
"Trained Words", "Untrained Words", "Untrained Words", "Comprehension",
"Comprehension"), chgacc = c(0.693669355, 0.512145161, 0.189221837,
0.19727383, 0.488085538, 0.080855379, 0.365701923, 0.331008065,
-0.405006036, -0.210909879, -0.135833333, 0.006145503), grouping = c("Active: 1 Month Post",
"Active: 3 Months Post", "Active: 1 Month Post", "Active: 3 Months Post",
"Active: 1 Month Post", "Active: 3 Months Post", "Sham: 1 Month Post",
"Sham: 3 Months Post", "Sham: 1 Month Post", "Sham: 3 Months Post",
"Sham: 1 Month Post", "Sham: 3 Months Post"), time = c("1 Month Post",
"3 Months Post", "1 Month Post", "3 Months Post", "1 Month Post",
"3 Months Post", "1 Month Post", "3 Months Post", "1 Month Post",
"3 Months Post", "1 Month Post", "3 Months Post")), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -12L), spec = structure(list(
cols = list(tdcs = structure(list(), class = c("collector_character",
"collector")), type = structure(list(), class = c("collector_character",
"collector")), chgacc = structure(list(), class = c("collector_double",
"collector")), grouping = structure(list(), class = c("collector_character",
"collector")), time = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1L), class = "col_spec"))
And here is my code thus far:
library(tidyverse)
colorpicks <- c("darkslategray", "azure3","blue3", "cyan")
plot1 <- ggplot(data=results, aes(tdcs, chgacc, fill = grouping)) +
facet_wrap(~type, dir = "h") +
theme_bw()+
geom_col(width = 0.7, position = position_dodge(width = 0.7)) +
scale_fill_manual(values = colorpicks, labels = c('Active - 1 Month Post','Active - 3 Months Post',
'Sham - 1 Month Post', 'Sham - 3 Months Post'))+
scale_y_continuous(labels = scales::label_percent(accuracy = 1),limits = (c(-0.5,1))) +
labs(x = "Phase", y = "Change from Baseline", fill = 'Phase & \nTime Point')+
scale_x_discrete(labels = c('Active','Sham'))+
theme(plot.title = element_text(size = 16),
strip.text = element_text(size = 12),
axis.text = element_text(size = 12),
axis.title.y = element_text(size = 14),
legend.text=element_text(size=11))
plot1
I have seen some solutions that involve using facet_wrap, but I am already using that for the 3 data categories. Is something like this possible?