ddediu / AdhereR

Computation of adherence to medications from Electronic Healthcare Data in R
26 stars 6 forks source link

Factors mess up colors in plots #8

Closed Masswear closed 5 years ago

Masswear commented 5 years ago

Medications are plotted in black instead of different colors when medication.class is of type factor

test_med_events <- data.frame(PATIENT_ID = rep(1,5),
                              DATE = c("2015-01-01", "2015-02-01", "2015-03-01", "2015-02-15", "2015-03-01"),
                              PERDAY = c(2,2,1,2,1),
                              CATEGORY = c("medA", "medA", "medA", "medB", "medB"),
                              DURATION = c(31,28,31,13,31),
                              stringsAsFactors = TRUE)
cma0 <- CMA0(test_med_events,
             ID.colname="PATIENT_ID",
             event.date.colname="DATE",
             event.duration.colname="DURATION",
             event.daily.dose.colname="PERDAY",
             medication.class.colname="CATEGORY",
             followup.window.start=0,
             followup.window.start.unit="days",
             followup.window.duration=2*365,
             followup.window.duration.unit="days",
             observation.window.start=1,
             observation.window.start.unit="days",
             observation.window.duration=365,
             observation.window.duration.unit="days",
             date.format="%Y-%m-%d",
             summary="Base CMA")
plot(cma0, col.cats = rainbow, show.legend = TRUE)
ddediu commented 5 years ago

Hopefully fixed in all plotting functions (it was something weird to do with ifelse() and factors being coerced to integer!)