I'm currently working on some plots, and I faced a problem that I could not solve right now based on my current ggplot2 knowledge.
I'm going to try and explain my problem using fictional data that I created in R. Below I leave the output of str command on my fictional dataframe:
'data.frame': 15 obs. of 4 variables:
$ x: Factor w/ 2 levels "0","1": 2 1 2 1 1 1 2 2 1 2 ...
$ y: Factor w/ 2 levels "0","1": 1 2 2 1 2 2 2 1 1 1 ...
$ w: Factor w/ 2 levels "0","1": 2 1 2 2 1 1 1 1 2 2 ...
$ z: Factor w/ 2 levels "0","1": 2 1 2 2 1 1 2 2 1 2 ...
As you can see those are all dichotomous variables. Let's consider my dependent variable is y. The plot I want to do is a bar chart like this image below:
I really wanted to make a plot like this one. And another one like this but also add a bar with prevalence of y comparing the group with 1 on independent variable (x, w and z) with the ones with 0 on independent variables (on x, w and z). So, in this second idea, it would be 6 bars instead of only 3. But any of the two ideas would work wonderfully for what I need to do. Thanks in advance for the community, you are always really helpful.
Example data:
d <- structure(list(x = structure(c(2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L), .Label = c("0", "1"), class = "factor"), y = structure(c(1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L), .Label = c("0", "1"), class = "factor"), w = structure(c(2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L), .Label = c("0", "1"), class = "factor"), z = structure(c(2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L), .Label = c("0", "1"), class = "factor")), row.names = c(NA, -15L), class = "data.frame")




