I produced some kind of "pyramid plot" or "back to back plot" to compare two groups and examine the proportion of a certain event in each group (in this example the administering of certain drugs).
I am 90% of the way there thanks to the ggh4x-package enabling me to mirror the scales. This is the code I used to produce the first plot below:
library(ggplot2)
library(ggh4x)
data <- data.frame(group = c("Group 1", "Group 1", "Group 2", "Group 2", "Group 1", "Group 1", "Group 2", "Group 2", "Group 1", "Group 1", "Group 2", "Group 2"),
administered = c("no", "yes", "no", "yes", "no", "yes", "no", "yes", "no", "yes", "no", "yes"),
medication = c("DRUG A with a long name", "DRUG A with a long name", "DRUG A with a long name", "DRUG A with a long name", "DRUG B", "DRUG B", "DRUG B", "DRUG B", "DRUG C", "DRUG C", "DRUG C", "DRUG C"),
count = c(100,200,50,88,99,300,77,45,12,0,9,27))
ggplot(data, aes(x = medication,
y = count,
fill = administered)) +
geom_col(position = "fill") +
ylab("proportion") +
scale_fill_manual(values = c("no"="#FF0000FF",
"yes"="#0000FFFF"))+
theme(axis.ticks.y = element_blank()) +
facet_wrap2(~ group, scales = "free") +
facetted_pos_scales(y = list(
scale_y_reverse(labels = scales::percent),
scale_y_continuous(labels = scales::percent))) +
coord_flip()
I would like to get rid of the labels in the first facet and centre the labels between the first and second facets. My desired result is something like this:
Your help is greatly appreciated!


