I am trying to create a barplot that is colored by both the variable used for the “fill” function but also by the variable being faceted by.
Currently my code is as follow:
data24 %>%
count(Disease, Diseae.Category, Case.Status) %>%
mutate(count=n,
pct=n/sum(n)) %>%
ggplot(aes(x=Disease, y = n, fill = Case.Status)) +
geom_bar(stat = "identity") +
facet_grid(Diseae.Category ~., scales = "free", space = "free") + coord_flip() +
scale_fill_manual(values = c("lightgrey", "skyblue"), labels = c("NAC","Confirmed")) +
#geom_text(aes(label=paste0(n)), position=position_stack(vjust = 0.5), size = 3, color = "black") +
theme_minimal() + theme(legend.title = element_blank(),axis.title.y = element_blank()) + theme(panel.spacing = unit(2, "lines")) +
ylab("Count")
And the graph looks like:
(blue = reports that are confirmed cases, gray = reports that are not a case)
I would like for it to look more like:
In the second image, the filled color is different by group. Is this possible?
Thank you in advance!!