ddediu / AdhereR

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

Whitespace when no CMA #174

Closed dffyfe closed 3 years ago

dffyfe commented 3 years ago

Hi Dan,

When there is no CMA available and the partial CMA bar isn't being plotted, the size of the plot isn't adjusted to fit. I also think the positioning of the y-axis might be off but not 100%. Reprex below;

CMAExampleSpace <- structure(list(CHI = c(9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 
9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 
9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 
9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 
9999L, 9999L, 9999L, 9999L, 9999L, 9999L, 9999L), AdhereRLabel2 = c("Drug 02", 
"Drug 02", "Drug 02", "Drug 02", "Drug 02", "Drug 02", "Drug 02", 
"Drug 02", "Drug 02", "Drug 06", "Drug 03", "Drug 03", "Drug 03", 
"Drug 03", "Drug 03", "Drug 03", "Drug 03", "Drug 03", "Drug 03", 
"Drug 07", "Drug 04", "Drug 04", "Drug 04", "Drug 04", "Drug 04", 
"Drug 04", "Drug 04", "Drug 04", "Drug 04", "Drug 08", "Drug 01", 
"Drug 01", "Drug 01", "Drug 01", "Drug 01", "Drug 01", "Drug 01", 
"Drug 01", "Drug 01", "Drug 12"), DisDate = structure(c(18201, 
18203, 18256, 18347, 18408, 18611, 18612, 18616, 18642, 18642, 
18201, 18203, 18256, 18347, 18408, 18611, 18612, 18616, 18642, 
18642, 18201, 18203, 18256, 18347, 18408, 18611, 18612, 18616, 
18642, 18642, 18201, 18203, 18256, 18347, 18408, 18611, 18612, 
18616, 18642, 18642), class = "Date"), MarkerLength = c(28, 60, 
28, 28, 55, 60, 60, 28, 28, 28, 28, 60, 28, 28, 55, 60, 60, 28, 
28, 28, 28, 60, 28, 28, 55, 60, 60, 28, 28, 28, 28, 60, 28, 28, 
55, 60, 60, 28, 28, 28), Quantity = c(28L, 28L, 28L, 28L, 28L, 
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L), PISSectionCode = c(901L, 
901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 
901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 
901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 901L, 
901L, 901L, 901L, 901L, 901L, 901L), AN = c("FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", "FOLIC ACID", 
"FOLIC ACID", "FOLIC ACID", "FOLIC ACID"), Indexing = c(1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 9L, 1L, 2L, 3L, 4L, 
5L, 6L, 7L, 8L, 9L, 9L), X = c(NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
)), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", 
"12", "11", "21", "31", "41", "51", "61", "71", "81", "91", "121", 
"13", "22", "32", "42", "52", "62", "72", "82", "92", "122", 
"14", "23", "33", "43", "53", "63", "73", "83", "93", "123"), class = "data.frame")

cma7 <- CMA_sliding_window(
  CMA.to.apply = "CMA7",
  data=CMAExamplesSpace, #[CMAExamples$AdhereRLabel2 != "Drug 12",],
  ID.colname = "AdhereRLabel2",
  js.tooltip.colname = "AN",
  event.date.colname = "DisDate", 
  event.duration.colname = "MarkerLength", 
  #medication.groups = medgroupsdf,
  #medication.groups = "AdhereRLabel2",
  date.format = "%Y-%m-%d",
  followup.window.start = as.Date("2019-11-01"),
  followup.window.start.unit = "days",
  followup.window.duration = 500,
  followup.window.duration.unit = "days",
  observation.window.start = as.Date("2020-01-01"),
  observation.window.start.unit = "days",
  observation.window.duration = 366,
  observation.window.duration.unit = "days",
  sliding.window.start = 0,
  sliding.window.start.unit = "days",
  sliding.window.duration = 365,
  sliding.window.duration.unit = "days",
  sliding.window.step.duration = 365,
  sliding.window.step.unit = "days",
  sliding.window.no.steps = 1,
)

plot(cma7, 
     show.period = "dates", 
     period.in.days = 60,
     show.legend = FALSE,
     ylab = c(withCMA = "Section - Drug Name"),
     cex.axis = 1,
     title = "CHIno",
     #col.cats = colorblind,
     CMA.cex = 0.8,
     plot.CMA = F,
     plot.CMA.as.histogram = F,
     force.draw.text = TRUE,
     CMA.plot.ratio = 0.000000000000000000000001,
     min.plot.size.in.characters.horiz=0,
     min.plot.size.in.characters.vert=0)
ddediu commented 3 years ago

This seems to happen only when a patient without any prescription in the window is plotted alongside another one that does... I'll look into it anyways (BTW, data = CMAExamplesSpace should be data = CMAExampleSpace :))

dffyfe commented 3 years ago

Hi, yeah probably more relevant to my use case (using drugs as patients) than others. It's happening because plotids and cmas is unfiltered in the vert.space.cmas calc, I think.

ddediu commented 3 years ago

No worries: so, I'm trying to still plot the empty ones, but would you rather prefer not to plot them at all?

ddediu commented 3 years ago

... personally I think it still informative to see them, even with empty bars and "?" estimates

ddediu commented 3 years ago

Like this: image

dffyfe commented 3 years ago

I prefer them plotted too.

I think this line in plotting.R needs removed if they are to be kept;

cma$data <- cma$data[ !(cma$data[,col.patid] %in% patids.no.events.to.plot), ];

As a workout for CMA10 and 11 I used used return(0) rather than return(CMAReal) so it would always plot as 0%, but '?' makes more sense.

ddediu commented 3 years ago

so the above plot is ok for you? If so, I'll fix it so...

dffyfe commented 3 years ago

Yeah the above is best I would say!

22 Nov 2021 09:31:45 Dan Dediu @.***>:

so the above plot is ok for you? If so, I'll fix it so...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub[https://github.com/ddediu/AdhereR/issues/174#issuecomment-975326997], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ARVBNWQLDFC7KY7VHCUQ2I3UNIEYDANCNFSM5ICAENXA]. Triage notifications on the go with GitHub Mobile for iOS[https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675] or Android[https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD8AAAA/CAYAAABXXxDfAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAmSURBVGiB7cEBDQAAAMKg909tDwcUAAAAAAAAAAAAAAAAAAAAJwY+QwABivJx1AAAAABJRU5ErkJggg==###24x24:true###][Tracking image][https://github.com/notifications/beacon/ARVBNWS4GSXO2XK5I7UWYF3UNIEYDA5CNFSM5ICAENXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHIRE6FI.gif]

ddediu commented 3 years ago

should be fixed in the devel brach