bar graphs in ggplot2

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?

I would suggest that you try a plot with geom_point() rather than with bars. I think you want to show the relationship between to continuous quantities and a plot with points does that well. You will have to rearrange your data to have a column for the child and one for the caregiver but that can be done without too much trouble.

Not sure if I can do that. I am only interested in percentage of glottals (grey). The non-glottal data are whited out.

So you want to pair the data by child so that Adam and Adam mum form one pair and so on? I would try having one column designating the child and another showing whether the given point relates to the child or the caregiver. You could then fill the columns based on this second column. If you post some of your data, someone could give more specific advice. You can post the output of


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.