Side-by-Side Plots of Oral Chemotherapy Data Before and After Processing

69 views
Skip to first unread message

Paul M

unread,
Jan 9, 2019, 2:14:11 PM1/9/19
to ggplot2
Hello All,

New to this group. Don't make a lot of graphs in my day-to-day work. Need some help making graphs that appear to be a little beyond my current abilities.

Attached is a code file that should help illustrate what I'm trying to accomplish.

I want to create a series of side-by-side graphs for oral chemotherapy among a set of cancer patients. The left side of each graph would show the unprocessed data for a given patient and drug. The right side would show what the data look like after processing. The processing combines overlapping intervals within each drug into a single interval. It then combines non-overlapping intervals that are separated by a sufficiently small amount of time into a single interval. For testing purposes, sufficiently small has been set to <= 63 days (three 21-day cycles).

The first plot generated by the attached code should do a pretty good job of showing what a left-side ought to look like. One of the purposes of this exercise is to depict graphically a specific principle. Specifically, the idea that, if you sequence the start dates and end dates for a set of overlapping intervals, the end of a combined interval will always occur where the number of start dates equals the number of end dates. Hence the counts at the bottom of the graph. Hopefully the graph will help make clear why this should be the case.

The second plot does a less of a good job showing what a right side ought to look like. Hopefully it will be sufficient for practical purposes though. The main deficiency I think is that the scaling for the y-axis is a bit off. If the best way to depict the before and after picture is to have side-by-side graphs, then I imagine the y-axis scaling for the right side will be set to match the y-axis scaling for the left side. Based on what I think I know about ggplot2, it occurred to me that a solution might automatically set the scaling for the y-axis on the right hand side to match that on the left. I could very well be wrong about that though.

One thing I'm struggling with is the scaling of the x-axis on both graphs. In neither case, does it reflect the time/date data. In the first graph, this obscures the fact that only 2 days elapse between 2014-08-04 and 2014-08-06 (which is <= 63). So it might not be immediately intuitive why there is only one interval on the right-hand side and not two.

The x-axis on the right side graph is also showing years and not start dates and end dates.

Given that I don't make all that many graphs, I'm also open to the possibility that my idea of having a left and right side isn't the best way to depict the before and after picture. So I'd be quite interested in seeing other ideas from people who have a better sense of how to go about designing a good graph.

Thanks,

Paul

Oral Chemotherapy Plot Code.r

polc1410

unread,
Jan 9, 2019, 5:49:37 PM1/9/19
to ggplot2
Ah - as simple as needing:

library (ggplot2) 
library (ddplyr)

to get the code to run.  It was the ddplyr that was needed.

polc1410

unread,
Jan 9, 2019, 5:49:37 PM1/9/19
to ggplot2
Chemotherapy is my thing... so your post caught my eye.  Not sure I understand what you are trying to show. But I wonder if thats a translation issue.

I'm no expert in R but like to dabble. I'm definitely no expert in ggplot. But I thought I'd take a look and see what you are doing.

I can't get the attached code to run.

It fails on the line:

p1 <- raw_data %>%
  filter(profile_key == 1453 & generic_name == "tamoxifen") %>%
  ggplot() +

with the error: 

Error in raw_data %>% filter(profile_key == 1453 & generic_name == "tamoxifen") %>%  : 
  could not find function "%>%"

Not syntax I'm familiar with, means I can't get it to run any more than that...

polc1410

unread,
Jan 9, 2019, 6:12:10 PM1/9/19
to ggplot2


On Wednesday, 9 January 2019 19:14:11 UTC, Paul M wrote:
The processing combines overlapping intervals within each drug into a single interval. It then combines non-overlapping intervals that are separated by a sufficiently small amount of time into a single interval. For testing purposes, sufficiently small has been set to <= 63 days (three 21-day cycles).

OK  I kind of get this. BUT it seems a bit odd. why portray something as continuing that didn't.  Perhaps 63 days is disproportionately wrong.  But I suspect this is a side issue!

The first plot generated by the attached code should do a pretty good job of showing what a left-side ought to look like. One of the purposes of this exercise is to depict graphically a specific principle. Specifically, the idea that, if you sequence the start dates and end dates for a set of overlapping intervals, the end of a combined interval will always occur where the number of start dates equals the number of end dates. Hence the counts at the bottom of the graph. Hopefully the graph will help make clear why this should be the case.

The second plot does a less of a good job showing what a right side ought to look like. Hopefully it will be sufficient for practical purposes though. The main deficiency I think is that the scaling for the y-axis is a bit off. If the best way to depict the before and after picture is to have side-by-side graphs, then I imagine the y-axis scaling for the right side will be set to match the y-axis scaling for the left side. Based on what I think I know about ggplot2, it occurred to me that a solution might automatically set the scaling for the y-axis on the right hand side to match that on the left. I could very well be wrong about that though.

Is the best way to depict this side by side? Why not depict it above and below, or actually,,, on the same graph even? Same graph with a different coloured line say at y = 0.5 would show the observations extending through....
 

One thing I'm struggling with is the scaling of the x-axis on both graphs. In neither case, does it reflect the time/date data. In the first graph, this obscures the fact that only 2 days elapse between 2014-08-04 and 2014-08-06 (which is <= 63). So it might not be immediately intuitive why there is only one interval on the right-hand side and not two.

First graph is showing dates as characters not dates...

 start_date = c(
        "2013-02-11", "2010-06-17", "2013-07-18", "2013-07-18", "2014-01-21", "2014-07-24", "2014-08-06", 
        "2010-03-17", "2011-10-26", "2012-07-24", "2013-07-25", "2015-08-12", "2015-11-24", "2013-07-26", "2014-07-30"
      )

Needs to do something to make that a date (it could just say "a point in time" "another point in time" etc.

In the processed data you define:

start_date = structure(c(15747, 14777, 15904, 14685, 15273), class = "Date"),
    

The x-axis on the right side graph is also showing years and not start dates and end dates.

This is probably correct... ! 

Paul M

unread,
Jan 11, 2019, 8:50:45 AM1/11/19
to ggplot2
Thanks for taking a look at my post and for your comments. Sorry about not including the information about packages to be attached. Suppose I will continue working on this.

Thanks,

Paul
Reply all
Reply to author
Forward
0 new messages