Last active
December 15, 2016 09:54
-
-
Save n8thangreen/8401789 to your computer and use it in GitHub Desktop.
Length of stay plotting script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data_long = melt(CDIdata, id.vars=c("rowID", "ribotype", "severe", "LoS.total", "LoS.preinf", "LoS.postinf", "discharge.status")) | |
| data_long$value = as.numeric(as.character(data_long$value)) | |
| # Change discharge to death in hospital | |
| data_long$variable = factor(data_long$variable, levels=c(unique(as.character(data_long$variable)), "Death in hospital")) | |
| d = data_long$variable=="Discharged" & data_long$discharge.status == "3" | |
| data_long$variable[d] = "Death in hospital" | |
| #write.csv(data_long, file="data_long.csv") | |
| # Reorder legend levels | |
| data_long = data_long[order(data_long$variable,as.numeric(as.character(data_long$LoS.total))),] | |
| # Reorder grouping levels by LENGTH OF STAY | |
| groupID = factor(data_long$rowID, levels = c(as.list(unique(as.character(data_long$rowID))))) | |
| i = ggplot(data_long, aes(y = groupID, x = value, group= rowID, col=variable)) | |
| i + geom_line(size=1) + geom_point() + theme(axis.text.y = element_blank()) + | |
| labs(x ="Time in hospital (days)", y = "Patient",title = "Length of Stay infected") +opts(panel.background = theme_rect(fill='white', colour='black')) + | |
| scale_color_manual(values = c("grey", "black", "black", "red")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment