Mixed Variable Type - Stacked Barplot

Hi All,

I would like to produce a stacked barplot with variables on the horizontal axis, yet some variables have different responses.

Some variables are 'Y/N' responses. Some variables are 'Old/Young'. And some of the variables are a Likert scale of 0-5.

Therefore, I would like to plot these in a stacked barplot form, with each variable type encoded with a different colour palette, and with a legend reflecting the different palettes/variable types.

I wondered if someone could help with this, please? Would be greatly appreciated.

X1<-c("N","N","N","N","Y","N","Y","N","N","N","N","N","Y","N","N","Y","N","N","N","Y","N","Y","Y","N","N","Y","Y","Y","N","N","N","N","N","N","N","N","Y","N","Y","N","N","N","N","Y","N","N","Y","N","Y","Y","N","Y","N","N")
X2 <-c("N","N","N","N","Y","N","Y","N","N","N","N","N","Y","N","N","Y","N","N","N","Y","N","Y","Y","N","N","Y","Y","Y","N","N","N","N","N","N","N","N","Y","N","Y","N","N","N","N","Y","N","N","Y","N","Y","Y","N","Y","N","N")
X3<-c(1,1,0,1,2,0,0,0,0,0,1,1,1,2,0,1,2,1,1,0,0,0,4,1,0,0,0,0,1,0,2,0,0,2,1,1,0,0,0,1,1,0,1,0,1,0,1,1,0,1,0,1,1,1)
X4 <-c("YouNg","Old","Old","YouNg","Old","Old","Old","YouNg","YouNg","YouNg","Old","Old","Old",
       "Old","Old","Old","Old","YouNg","Old","Old","Old","YouNg","YouNg","Old","Old","Old",
       "Old","Old","Old","Old","Old","Old","Old","YouNg","Old","YouNg","Old","YouNg","Old",
       "Old","YouNg","Old","YouNg","YouNg","Old","Old","Old","YouNg","Old","Old","Old","YouNg", "Old", "Old")

Y <- data.frame(X1, X2, X3, X4)

There won't be an easy/natural way to do this; as it would seem to fight the tidyness principles of ggplot2.
To achieve this you would need to split the data up in to groups of variables with compatible factor levels. Construct the segment of stacked plot suitable for each group; then patchwork these multiple plots together to make the illusion that they share common axis; and also merge together the disparate legends.

Thanks @nirgrahamuk. Yeah, I've found it challenging so far. I'll keep plugging away, however. Thanks again.

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.