I am using patient dataset to determine which medications (amiodarone & digoxin) they are taking.
Here is the classifer I am using
topcat$aARGroup <- with(topcat, ifelse((is.na(amiodarone) & is.na(digoxin)), 'Missing data',
ifelse((amiodarone == 1 & digoxin == 0), 'Amiodarone',
ifelse((amiodarone == 0 & digoxin == 1), 'Digoxin',
felse((amiodarone == 1 | digoxin == 1), 'Combination', 'No usage')))))
topcat$aARGroup <- factor(topcat$aARGroup, levels = c('Amiodarone','Digoxin','Combination','None','Missing data'))
Unfortunated all data are 'NA' since it is not recorded. So it is 100% "Missing data". I am trying to generate a bar plot and have all medication claases displayed in the legend, eventhough all classes except "missing data" are empty.
ggplot(topcat, aes(x = aARGroup))+
theme(axis.text.x=element_blank(), axis.ticks.x=element_blank())+
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count") +
geom_text(aes( label = scales::percent(..prop.., accuracy = 0.1),
y= ..prop.. ), stat= "count", vjust = -.5, size = 5) +
scale_y_continuous(labels=scales::percent) +
labs(y="Percentage",x="Anti Arrhythmic drugs")+
scale_x_discrete(limits=c('Amiodarone','Digoxin','Combination','No usage','Missing data'))+
scale_fill_discrete(labels=c('Amiodarone','Digoxin','Combination','No usage','Missing data'))+
theme(text=element_text(size=18), legend.position = "bottom", legend.title = element_blank())+
theme(strip.text=element_text(size=11))
So the code does not produce the expected results.
- It does not show all classes
- It shows all patients are taking Amiodarone, when underlying data all "Missing data"
Here is the output
Here is the dataframe view
Thank you for your help!