Open ddediu opened 3 years ago
See also issue #101
Might also be useful for normal plotting (Suggested by Tsaone Tamuhla)
This turns out to be pretty much and might require some serious changes to the code. However, as a workaround, there's now a parameter do.not.draw.plot
to the plot()
function which is intended to only plot the legend (at coordinates (0,0)), which, combined with get.legend.plotting.area()
should allow the placement of the legend outside the CMA plot
Hello @ddediu,
Please find below R code to plot cma0 plot and legends separate. I think this may be helpful for other researchers.
Thanks in advance...
library(AdhereR) library(dplyr)
df <- med.events %>% filter(PATIENT_ID %in% c(37,76))
head(med.events)
cma0 <- CMA0(data=df, # use the two selected patients ID.colname="PATIENT_ID", # the name of the column containing the IDs event.date.colname="DATE", # the name of the column containing the event date event.duration.colname="DURATION", # the name of the column containing the duration event.daily.dose.colname="PERDAY", # the name of the column containing the dosage medication.class.colname="CATEGORY", # the name of the column containing the category followup.window.start=0, # FUW start in days since earliest event observation.window.start=182, # OW start in days since earliest event observation.window.duration=365, # OW duration in days date.format="%m/%d/%Y"); # date format (mm/dd/yyyy)
par(mfrow = c(1,2))
plot(cma0, # the object to plot align.all.patients = TRUE, # align all patients for easier comparison patients.to.plot = NULL, # a vector of string containing list of patients to be plot duration = 365*2, # a number, total duration (in days) of the whole period to plot align.first.event.at.zero = FALSE, # Logical,the first event be placed at the origin of the time axis? show.period = c("dates","days")[2], # show period in dates or days (if align.all.patients == TRUE then plot will show x axis in days only) period.in.days = 30, # the number of days at which the regular grid is drawn show.legend = FALSE, # Logical, should the legend be drawn? bw.plot = FALSE)
plot(cma0, # the object to plot align.all.patients = TRUE, # align all patients for easier comparison patients.to.plot = NULL, # a vector of string containing list of patients to be plot duration = 365*2, # a number, total duration (in days) of the whole period to plot align.first.event.at.zero = FALSE, # Logical,the first event be placed at the origin of the time axis? show.period = c("dates","days")[2], # show period in dates or days (if align.all.patients == TRUE then plot will show x axis in days only) period.in.days = 30, # the number of days at which the regular grid is drawn show.legend = TRUE, # Logical, should the legend be drawn? bw.plot = FALSE, legend.x = "right", legend.y = "top", legend.bkg.opacity = 0.5, legend.cex = 0.35, legend.cex.title = 1, cex = 1, cex.axis = 0.45, do.not.draw.plot = TRUE) # logical, plot only legends if show.legend == TRUE
This would avoid crowding of the shiny plot and be better from an UI perspective