Skip to content

Instantly share code, notes, and snippets.

@n8thangreen
Last active December 15, 2016 09:54
Show Gist options
  • Select an option

  • Save n8thangreen/8401789 to your computer and use it in GitHub Desktop.

Select an option

Save n8thangreen/8401789 to your computer and use it in GitHub Desktop.
Length of stay plotting script
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