I’m trying to design a bar graph that represents percentages of complications among two cohorts (GLP and No GLP). I am using the data table and code below and I have included my current result as well as a depiction of the graph I’m trying to obtain.
Any help would be appreciated. I’m new to this. Data table below saved as GLPcomprate.
Cohort | Complication | Percentage |
---|---|---|
GLP | CSF_leak | 13.40 |
GLP | DVT | 5.74 |
GLP | UTI | 20.57 |
GLP | Constipation | 22.97 |
GLP | Pneumonia | 9.09 |
GLP | Post-operative infection | 6.22 |
GLP | Adverse Drug Effects | 4.79 |
GLP | Meningitis | 4.79 |
GLP | Post-operative Respiratory Failure | 4.79 |
GLP | Thyrotoxicosis | 4.79 |
GLP | Acute Kidney Injury | 11.96 |
GLP | Delirium | 4.79 |
No GLP | CSF_leak | 11.32 |
No GLP | DVT | 5.26 |
No GLP | UTI | 15.74 |
No GLP | Constipation | 24.73 |
No GLP | Pneumonia | 9.81 |
No GLP | Post-operative Infection | 5.26 |
No GLP | Adverse Drug Effects | 0.65 |
No GLP | Meningitis | 7.12 |
No GLP | Post-operative Respiratory Failure | 1.71 |
No GLP | Thyrotoxicosis | 1.00 |
No GLP | Acute Kidney Injury | 10.78 |
No GLP | Delirium | 2.46 |
Current code is below.
GLPcomprate <- read_excel("IIH_GLP_Years.xlsx", sheet = 6)
head(GLPcomprate)
ggplot(GLPcomprate, aes(x=Complication, y=Percentage, fill = Cohort)) +
geom_bar(stat = "identity", position = position_stack(), width = 1) +
geom_text(aes(label = paste(Percentage, "%")), vjust = -1) +
facet_wrap(~Cohort, strip.position = "bottom", scales = "free_x") +
theme(panel.spacing = unit(0, "lines"),
strip.background = element_blank(),
strip.placement = "outside ")
Current output:
enter image description here
Desired output (created on Excel):
enter image description here