I've been trying to differentiate between the patient and the medic values of my grouped barplot using ggpattern. I have been trying to have one bar shaded and the other blank but it has not worked out. I keep getting this output:
This is the code I used:
<hpvcom %>% select(HPV.Result, Result) %>%
group_by(HPV.Result, Result) %>%
summarise(sum_result = n()) %>%
ggplot(mapping = aes(x = Result, y = sum_result, fill = Result))
ggpattern::geom_bar_pattern(stat="identity", position = position_dodge(preserve = "single"), fill = "white",
colour = 'black',
pattern_density = 0.35,
pattern_fill = 'black',
pattern_colour = 'black', alpha= 1)
scale_y_log10()
geom_text(mapping = aes(label = paste0( "n:",sum_result)), position = position_dodge(width = 0.9), cex = 3.5, vjust = 1.5, color = "yellow")
scale_x_discrete(labels = c("Medic", "Patient"))
theme_classic2()
theme(panel.grid = element_blank())
theme_pubr()
facet_wrap(~ HPV.Result, scales = "free")
xlab("")
ylab("")
theme(plot.title = element_text(hjust = 0.5))
theme(legend.position = "none")>
This is the data:
<> copy_to(dput(hpvcom))
structure(list(HPV.Result = c("HPV 16 Positive", "HPV 16 Positive",
"HPV 16 Positive", "HPV 16 Positive", "HPV 16 Positive", "HPV 18 Positive",
"HPV 18 Positive", "HPV 18 Positive", "HPV 18 Positive", "HPV 18 Positive",
"HPV 18 Positive", "HPV 18 Positive", "HPV 18 Positive", "HPV 18 Positive",
"HPV 18 & OHR Positive", "HPV 18 & OHR Positive", "HPV 18 & OHR Positive",
"HPV 18 & OHR Positive", "HPV 18 & OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive", "HPV OHR Positive",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "HPV Negative", "HPV Negative",
"HPV Negative", "HPV Negative", "Invalid Result", "Invalid Result",
"Invalid Result", "Invalid Result", "Invalid Result", "Invalid Result",
"Invalid Result", "Invalid Result", "Invalid Result", "Invalid Result",
"Invalid Result", "Invalid Result", "Invalid Result", "Invalid Result",
"Invalid Result", "Invalid Result", "Invalid Result", "Invalid Result",
"Invalid Result", "Invalid Result"), Result = c("Patients_Result",
"Patients_Result", "Patients_Result", "Medics_Result", "Medics_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Medics_Result", "Medics_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Patients_Result", "Patients_Result", "Patients_Result",
"Patients_Result", "Medics_Result", "Medics_Result", "Medics_Result",
"Medics_Result"), Result.1 = c(0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L,
0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
1L, 1L)), class = "data.frame", row.names = c(NA, -426L))>
Any help with this would be appreciated!
CodePudding user response:
You just need to add pattern in geom_bar_pattern
pattern = rep(c('none','stripe'),6),
Pattern is the key part of geom_bar_pattern. You can choose from 'stripe' (default), 'crosshatch', 'point', 'circle', 'none'. And the length of pattern needs to be either one or the same as the data.