I am trying to combine two plots into one but on the same axis, not next to each other (no facet wrap). The issue with the data I have is there is overlap between two categories of data, ideally I could just gather them but that wouldn't work unless I made a third category which doesn't fit with the project I am doing.
Referencing this solution, I did the following
library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.0.3
#> Warning: package 'readr' was built under R version 4.0.3
library(ggplot2)
df<-
tibble::tribble(
~cohort1.1, ~cohort2.1, ~decreased_lvef,
"Yes", "No", "Yes",
"Yes", "No", "No",
"Yes", "Yes", "Yes",
"Yes", "No", "No",
)
one<-
df %>%
filter(cohort1.1 == "Yes") %>%
group_by(cohort1.1,decreased_lvef) %>%
count()
two<-
df %>%
filter(cohort2.1 == "Yes") %>%
group_by(cohort2.1,decreased_lvef) %>%
count()
one %>%
ggplot() +
geom_col(mapping = aes(x = cohort1.1, y = n, fill = decreased_lvef)) +
geom_col(data = two, mapping = aes(x = cohort2.1, y = n, fill = decreased_lvef))
Which doesn't put each column next to the other on the same axis.