Using ggplot2 geom_bar is there a way to subset two factors on the x axis and group pairs within them?
My dataset contains levels of glottals used in speech of children and their caregivers. Factors are Speaker
(a, amum, b, bmum ...), Category
(child, caregiver) and Pair
(a and amum ...).
My plot shows 22 speakers' levels of glottalisation using the following code:
ggplot(data1, aes(x = Speaker, fill=Glottals, fill = Category)) +
geom_bar(position ="fill") + scale_fill_manual(values = c("White", "grey")) + theme_minimal() + ggtitle ("Percent glottals for caregiver pairs") + ylab("Percent") + scale_y_continuous(labels = scales::percent) + xlab("Speaker") + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + theme(legend.position = "none")
with the following output:
Can you suggest a way to colour child and caregiver separately, and group them together on the x axis?