TreatmentPlot: 'TreatmentPlot-class'

Description Details Fields Examples

Description

A reference class used to create a treatment plot at a patient level.

Details

Once the TreatmentPlot class is created you need to prepare the plot using the CreatePlot method (object$CreatePlot()). Use the Add methods to add data, axes, labels and legends to the plot and then call the CloseScreens method (object$CloseScreens()) to finish. There is a list of methods below and an example.

List of methods which can be called using the syntax object$Method():

Data can be accessed using the @ operator E.G. object@data. Methods are accessed using the $ operator E.G. object$CreatePlot. Making a copy and then modifying the copy will cause the original to change since this is a reference class.

Fields

data

A data.frane containing patient key and treatment

patientKey

the name of the patientKey column

treatmentColumn

the name of the treatmentColumn

timeZeroColumn

the name of the column to use as time zero

legendElements

A list of elements to add to the legend. This is generated automatically. This is then used by AddLegend to add the legend to the plot

screens

A vector of screen numbers for the main plot and legend. This is set by CreatePlot. More details can be found in CloseScreens and the full documentation (screen)

xlim

The range the xaxis should encompass. This is set by CreatePlot

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
##########################################################################
# Create some dummy data for testing purposes
patientData = data.frame(
  patid = paste0("PT", 1:20), 
  treatment = c(rep("Placebo",10), rep("Treatment", 10)), 
  zeroDate = as.Date(rep(15000,20), origin = "1970-01-01"), stringsAsFactors = FALSE)

# End of treatment event
eventData = data.frame(
  patid = paste0("PT", 1:20), 
  EOT = as.Date(floor(runif(20,15040,15050)), origin = "1970-01-01", stringsAsFactors = FALSE)
)

# treatment X
treatmentData = data.frame(
  patid = paste0("PT", 1:20), 
  SOT1 = as.Date(floor(runif(20,15005,15010)), origin = "1970-01-01"),
  EOT1 = as.Date(floor(runif(20,15011,15015)), origin = "1970-01-01"),
  SOT2 = as.Date(floor(runif(20,15020,15025)), origin = "1970-01-01"),
  EOT2 = eventData$EOT,
  stringsAsFactors = FALSE)

# pauses to treatment x
treatmentPauses = data.frame(
  patid = sample(paste0("PT", 1:20), size = 10),
  SOT = as.Date(floor(runif(20,15030,15033)), origin = "1970-01-01"),
  EOT = as.Date(floor(runif(20,15034,15038)), origin = "1970-01-01"),
  stringsAsFactors = FALSE)


# treatment y
treatmentData2 = data.frame(
  patid = paste0("PT", 1:20), 
  SOT1 = as.Date(floor(runif(20,15005,15010)), origin = "1970-01-01"),
  EOT1 = as.Date(floor(runif(20,15011,15015)), origin = "1970-01-01"),
  SOT2 = as.Date(floor(runif(20,15020,15025)), origin = "1970-01-01"),
  EOT2 = eventData$EOT
  , stringsAsFactors = FALSE)


# treatment z, these are single day events with two possible doses
n = 300
treatmentDataSingle = data.frame(
  patid = paste0("PT", sample(1:20,size = n,replace = TRUE)), 
  treatmentTime = as.Date(floor(runif(n,15005,15040)), origin = "1970-01-01"),
  dose = sample(c(50,100), size = n, replace = TRUE),
  stringsAsFactors = FALSE
)

##########################################################################
# Create some EventDate objects for single date events
# Create some EventDuration objects for events over a number of days

# treatment x
tDuration = EventDuration(
  data = treatmentData,
  startDateColumns = c("SOT1","SOT2"),
  endDateColumns = c("EOT1", "EOT2"),
  label = "Treatment X",
  ypos = c(0.5,0.8),
  col = "blue"
)

# pause in treatment x, use white to clear this area of plot
tDurationPause = EventDuration(
  data = treatmentPauses,
  startDateColumns = c("SOT"),
  endDateColumns = c("EOT"),
  label = "Treatment X",
  ypos = c(0.5,0.8),
  col = "white"
)

# treatment y
tDuration2 = EventDuration(
  data = treatmentData2,
  startDateColumns = c("SOT1","SOT2"),
  endDateColumns = c("EOT1", "EOT2"),
  label = "Treatment Y",
  ypos = c(0.2,0.5),
  col = "orange"
)



library(sqldf)
# treatment z, dose 50mg
singleData = EventDate(
  sqldf("select * from treatmentDataSingle where dose == 50"),
  columns = "treatmentTime",
  label = "treatment Z (50mg)",
  col = "green",
  lwd = 3
)

# treatment z dose 100mg
singleData2 = EventDate(
  sqldf("select * from treatmentDataSingle where dose == 100"),
  columns = "treatmentTime",
  label = "treatment Z (100mg)",
  col = "green4",
  lwd = 3
)

# end of treatment event
EOTevent = EventDate(
  data = eventData,
  columns = "EOT",
  label = "End of treatment",
  col = "red"
)

##########################################################################
# The base plot just needs the patientKey, treatment and zeroDate

# Creat the the reference object
treatmentPlot = TreatmentPlot(patientData, "patid", "treatment","zeroDate")

# Prepare the plot area.
treatmentPlot$CreatePlot(xlim = c(0,50), numberRowsLegend = 1)
# Note: this function uses screens. It may be added to a current screen in a
# multiscreen plot. Unitentionally leaving screens open may cause problems.
# see ?split.screen for more details on screens

# add the event duration elements for treatments x and y
treatmentPlot$AddEventDuration(tDuration)
treatmentPlot$AddEventDuration(tDurationPause)
treatmentPlot$AddEventDuration(tDuration2)

# add the events for treatment z at both doses
treatmentPlot$AddEvent(singleData, ypos = c(0.5,1))
treatmentPlot$AddEvent(singleData2, ypos = c(0.5,1))

# add the end of treatment event
treatmentPlot$AddEvent(EOTevent)

# The following functions tidy up the plot
treatmentPlot$AddGrid(xDistance = 21, xSubDistance = 7)
treatmentPlot$AddTreatmentYAxis()
treatmentPlot$AddPatientKey()
treatmentPlot$AddXAxis()
treatmentPlot$AddXLabel("Time from Registration (days)")

# Add the legend
treatmentPlot$AddLegend(itemsOnRow = 4, xoffset = 0.05)
# legend items are stored everytime an event is added so we
# don't need to add extras here

# close the screens used by treatmentPlot
treatmentPlot$CloseScreens()
# Close all screens (not necesary for the example)
close.screen(all.screens = TRUE)

csmoxford/TreatmentData documentation built on May 3, 2019, 9:38 p.m.