[R] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!

Paul Miller pjmiller_57 at yahoo.com
Thu Mar 22 18:41:52 CET 2012


Hello All,

Want very much to learn how to plot patient drug timelines. Trouble is I need to figure out how to do this today. So not much time for me to struggle with it. Hoping someone can just help me out a bit.

Below are some sample data and code that produces what I think is the beginning of a very nice graph. 

Need to alter the code to:

1. Get the lines for the drugs to appear on the y-axis in the order that they appear in the data.

2. Decrease the vertical space between the line segments for each drug so they are fairly close to one another.

3. Remove the numbering from the x-axis.

4. Put the text for pattern above the graph (e.g., "Begin (A), Begin (B), End (B), End (A)"), either centered or left aligned.

5. Put the patient and line information below the text for pattern (e.g., "profile_key = 1, line = 1")

6. Output a separate graph for each patient and line of treatent.

Ultimately, I want to combine all the graphs into a single Word document. Or perhaps better yet, to create a pdf using LaTeX.

I'm going to continue to try and fugure this out as best I can. Any help with it will be greatly appreciated though.

Thanks,

Paul


connection <- textConnection("
1/1/Drug A/ Begin (A), Begin (B), End (B), End (A)/0.0000/21.000
1/1/Drug B/ Begin (A), Begin (B), End (B), End (A)/0.7143/18.000
1/2/Drug A/ Begin (A, B, C), End (A, B), End (C)/0.0000/20.000
1/2/Drug B/ Begin (A, B, C), End (A, B), End (C)/0.0000/20.000
1/2/Drug C/ Begin (A, B, C), End (A, B), End (C)/0.0000/36.000
2/1/Drug A/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/0.0000/7.429
2/1/Drug B/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ 0.0000/7.429
2/1/Drug C/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ 14.5714/21.857
2/1/Drug D/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ 25.4286/231.286
2/2/Drug A/ Begin (A, B), End (A, B)/0.0000/35.286
2/2/Drug B/ Begin (A, B), End (A, B)/0.0000/35.286
")

TestData <- data.frame(scan(connection, list(profile_key=0, line=0, drug="", pattern="", start_drug=0, stop_drug=0), sep="/"))
TestData <- TestData[TestData$profile_key == 2 & TestData$line == 1,]
TestData

require(reshape)
TestData <- melt(TestData, measure.vars = c("start_drug", "stop_drug"))
TestData

ggplot(TestData, aes(value, drug)) + geom_line(size = 6) + xlab("") + ylab("") + theme_bw() 
ggsave(file = "plot21.pdf")



More information about the R-help mailing list