Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe show the legend in a floating HTML element/outside the plot in Shiny? Also for basic plotting? #156

Open
ddediu opened this issue Feb 26, 2021 · 4 comments
Assignees
Labels
AdhereR(base) AdhereRViz enhancement (partial) work-around Not completely fixed, but a work-around is possible... suggestion Suggestion/investigation

Comments

@ddediu
Copy link
Owner

ddediu commented Feb 26, 2021

This would avoid crowding of the shiny plot and be better from an UI perspective

@ddediu ddediu added enhancement suggestion Suggestion/investigation AdhereRViz labels Feb 26, 2021
@ddediu ddediu self-assigned this Feb 26, 2021
@ddediu
Copy link
Owner Author

ddediu commented Mar 9, 2021

See also issue #101

@ddediu ddediu changed the title Maybe show the legend in a floating HTML element/outside the plot in Shiny? Maybe show the legend in a floating HTML element/outside the plot in Shiny? Also for basic plotting? Apr 5, 2022
@ddediu
Copy link
Owner Author

ddediu commented Apr 5, 2022

Might also be useful for normal plotting
(Suggested by Tsaone Tamuhla)

@ddediu
Copy link
Owner Author

ddediu commented May 19, 2022

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.plotto 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

@ddediu ddediu added the (partial) work-around Not completely fixed, but a work-around is possible... label May 19, 2022
ddediu added a commit that referenced this issue Jun 24, 2022
commit 5c1d4f9
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 24 17:39:41 2022 +0200

    As submitted to CRAN

commit fdeb7d8
Author: Dan Dediu <[email protected]>
Date:   Sat Jun 18 20:33:35 2022 +0200

    Fix CRAN check errors and warnings

commit a6d8423
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 17 16:43:49 2022 +0200

    Solve GitHub #190 by allowing the recovery of the mapping between events and episodes/sliding windows, and even plotting it

commit 5a74ae9
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 17 12:42:44 2022 +0200

    Implement return.mapping.events.sliding.window for CMA_sliding_window

commit 7768564
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 17 11:33:07 2022 +0200

    Fix GitHub #192: now  align.first.event.at.zero is FALSE by default

commit f0f3b5d
Author: Dan Dediu <[email protected]>
Date:   Thu Jun 16 23:39:57 2022 +0200

    The simple CMAs return .EVENT.USED.IN.CMA in event.info

commit 9b5975a
Author: Dan Dediu <[email protected]>
Date:   Wed Jun 15 16:28:13 2022 +0200

    Fix GitHub #191 and bump version to 0.8

commit 3cac87b
Author: Dan Dediu <[email protected]>
Date:   Mon Jun 6 16:46:45 2022 +0200

    Fix GitHub #184: Python 3 wrapper does not show anymore warnings about overriding some arguments

commit 85475b1
Author: Dan Dediu <[email protected]>
Date:   Mon Jun 6 16:15:44 2022 +0200

    Python3 wrapper: handle plotting complex CMAs with event intervals

commit 2880088
Author: Dan Dediu <[email protected]>
Date:   Mon Jun 6 16:14:31 2022 +0200

    Fix bug when plotting complex CMAs showing event intervals with custom column names

commit 37c25c7
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 18:13:47 2022 +0200

    Update the NEWS.md to reflect the Python 3 changes

commit 58d2b7d
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 18:11:18 2022 +0200

    Rebuild the Python3 vignette (and remove the junyper checkpoint)

commit 6c4a539
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 18:07:55 2022 +0200

    AdhereR works from Python 3 Jupyter Notebooks (and with rpy2)!

    I also update the vignette and added two notebook examples

commit bc77b21
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 15:06:44 2022 +0200

    Fix GitHub #184 and a bug with Python3 and plotting complex CMAs

commit 675d57a
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 14:05:24 2022 +0200

    Pyhton3 wrapper: handle medication groups (defined by a column in the data)

commit 17d6b22
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 11:29:49 2022 +0200

    Python 3 wrapper: finished updating plot() + small bug fixes

commit 8d5d13e
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 16:51:35 2022 +0200

    Python3 wrapper: add plot.partial.CMAs* to plot()

commit bac9449
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 13:43:37 2022 +0200

    Python3 wrapper: add CMA.cex to plot()

commit 9ed89d2
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 11:51:04 2022 +0200

    Python3 wrapper: add dose* to plot()

commit e641baa
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 10:52:01 2022 +0200

    Python3 wrapper: implemented medication.groups in plot()

commit a135ce3
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 19:31:06 2022 +0200

    Python3 wrapper: xlab, ylab & title added to plot()

commit 69e6575
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 12:54:08 2022 +0200

    Python3 wrapper: make col.cats in plot() work

commit be1a454
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 11:32:19 2022 +0200

    Fix bug: cex.title in plot() was not implemented

commit e1b5b65
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 11:08:08 2022 +0200

    Starting to update the Python3 wrapper to reflect the new parameters

commit c2ddb1a
Author: Dan Dediu <[email protected]>
Date:   Wed May 25 17:05:02 2022 +0200

    Fix GitHub #182: the vignette shows how to change an AdhereR plot

commit b19e6bd
Author: Dan Dediu <[email protected]>
Date:   Mon May 23 22:10:25 2022 +0200

    Fixes issue #181 (plotting with aligned patients) and shows how to use AdhereR with pipe

commit 05d02b4
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 19:21:46 2022 +0200

    Latest source packages AdhereR 0.7.1 and bump to AdhereRViz 0.2.1

commit 79a966f
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 19:19:16 2022 +0200

    Work-around for GitHub #156 by allowing the plotting of the legend only

commit 9e5a311
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 12:35:57 2022 +0200

    Fix #169 by forcing arguments.that.should.not.be.defined=NULL (smartly) in sliding windows and per episodes

commit 42a3a82
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 11:59:10 2022 +0200

    Shiny: make sure the event interval defaults are correctly reset on changing the CMA

commit cf985f3
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 11:51:36 2022 +0200

    Fix #179 (CMA class not correctly initialised/updated in Shiny)

commit 9348b76
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 19:19:00 2022 +0200

    Shiny UI allows plotting event intervals for sliding windows and per per episodes

    Controlled from Aesthetics -> Event intervals; default = FALSE

commit 6e28af7
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 16:22:25 2022 +0200

    AdhererViz: bump version and fix check warnings

commit e4f5d36
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 13:09:18 2022 +0200

    Fixes GitHub issue #172

commit af2443c
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 13:05:10 2022 +0200

    Per episodes can also show the event intervals and gaps

commit ae58093
Author: Dan Dediu <[email protected]>
Date:   Tue May 17 14:44:20 2022 +0200

    Update documentation and fix check warnings

commit 24eb65e
Author: Dan Dediu <[email protected]>
Date:   Tue May 17 14:27:27 2022 +0200

    Plotting events and gaps seems to work for sliding windows

commit a51e0b1
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 13:25:32 2022 +0200

    Plotting intervals and gaps for sliding windows seems to work (but needs testing)

commit 95facec
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 11:14:48 2022 +0200

    ... actually, it does make sense to compute the inner.event.info even for overlapping windows (it is the user's problem to use them or not)

commit 9426ed5
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 11:06:24 2022 +0200

    Don't compute the inner.event.info if the sliding windows are overlapping

commit f3ac228
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 10:22:04 2022 +0200

    Don't print inner.event.info if present for per_episode and sliding_window objects

commit f0c6a68
Author: Dan Dediu <[email protected]>
Date:   Tue Apr 5 19:57:25 2022 +0200

    Now plot() respects the order of patients given through patients.to.plot

commit f8cfb67
Author: Dan Dediu <[email protected]>
Date:   Wed Nov 24 17:31:12 2021 +0100

    GitHub #172 : initial plotting of inner event intervals

commit 049760a
Author: Dan Dediu <[email protected]>
Date:   Wed Nov 24 16:56:02 2021 +0100

    Fix GitHub #175

    + some other preliminary work on plotting event intervals in sliding windows and per intervals (but nothing user-visible yet)

commit ac22abe
Author: Dan Dediu <[email protected]>
Date:   Mon Nov 22 12:44:14 2021 +0100

    Fix GitHub #174 (plus a small bug fix when plotting as a time series with 1 point)

    Now the placeholder for partial CMAs is plotted even if they don't have one...

commit 6c9846e
Author: Dan Dediu <[email protected]>
Date:   Sun Nov 7 23:56:53 2021 +0100

    GitHub #172

    Proof-of-concept that I can return the full event.info from sliding windows -> it adds overheads so disabled by default, but can be enabled by forcing the new argument return.inner.event.info to TRUE
ddediu added a commit that referenced this issue Jul 6, 2022
commit c2735f5
Author: Dan Dediu <[email protected]>
Date:   Tue Jul 5 17:37:50 2022 +0200

    Bugfix 0.8.1

commit c3964db
Author: Dan Dediu <[email protected]>
Date:   Mon Jun 27 13:28:30 2022 +0200

    Fix CMA_polypharmacy() crash in 0.8.0

commit a856c89
Author: Dan Dediu <[email protected]>
Date:   Sat Jun 25 11:55:09 2022 +0200

    Julia: check that RCall, R and AdhereR/AdhereRViz are installed and work

commit 47a5f2b
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 24 20:58:33 2022 +0200

    Bump version to 0.8.1

commit 9b33030
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 24 20:56:41 2022 +0200

    Starting to work on the Julia bridge

commit 5c1d4f9
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 24 17:39:41 2022 +0200

    As submitted to CRAN

commit fdeb7d8
Author: Dan Dediu <[email protected]>
Date:   Sat Jun 18 20:33:35 2022 +0200

    Fix CRAN check errors and warnings

commit a6d8423
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 17 16:43:49 2022 +0200

    Solve GitHub #190 by allowing the recovery of the mapping between events and episodes/sliding windows, and even plotting it

commit 5a74ae9
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 17 12:42:44 2022 +0200

    Implement return.mapping.events.sliding.window for CMA_sliding_window

commit 7768564
Author: Dan Dediu <[email protected]>
Date:   Fri Jun 17 11:33:07 2022 +0200

    Fix GitHub #192: now  align.first.event.at.zero is FALSE by default

commit f0f3b5d
Author: Dan Dediu <[email protected]>
Date:   Thu Jun 16 23:39:57 2022 +0200

    The simple CMAs return .EVENT.USED.IN.CMA in event.info

commit 9b5975a
Author: Dan Dediu <[email protected]>
Date:   Wed Jun 15 16:28:13 2022 +0200

    Fix GitHub #191 and bump version to 0.8

commit 3cac87b
Author: Dan Dediu <[email protected]>
Date:   Mon Jun 6 16:46:45 2022 +0200

    Fix GitHub #184: Python 3 wrapper does not show anymore warnings about overriding some arguments

commit 85475b1
Author: Dan Dediu <[email protected]>
Date:   Mon Jun 6 16:15:44 2022 +0200

    Python3 wrapper: handle plotting complex CMAs with event intervals

commit 2880088
Author: Dan Dediu <[email protected]>
Date:   Mon Jun 6 16:14:31 2022 +0200

    Fix bug when plotting complex CMAs showing event intervals with custom column names

commit 37c25c7
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 18:13:47 2022 +0200

    Update the NEWS.md to reflect the Python 3 changes

commit 58d2b7d
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 18:11:18 2022 +0200

    Rebuild the Python3 vignette (and remove the junyper checkpoint)

commit 6c4a539
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 18:07:55 2022 +0200

    AdhereR works from Python 3 Jupyter Notebooks (and with rpy2)!

    I also update the vignette and added two notebook examples

commit bc77b21
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 15:06:44 2022 +0200

    Fix GitHub #184 and a bug with Python3 and plotting complex CMAs

commit 675d57a
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 14:05:24 2022 +0200

    Pyhton3 wrapper: handle medication groups (defined by a column in the data)

commit 17d6b22
Author: Dan Dediu <[email protected]>
Date:   Tue May 31 11:29:49 2022 +0200

    Python 3 wrapper: finished updating plot() + small bug fixes

commit 8d5d13e
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 16:51:35 2022 +0200

    Python3 wrapper: add plot.partial.CMAs* to plot()

commit bac9449
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 13:43:37 2022 +0200

    Python3 wrapper: add CMA.cex to plot()

commit 9ed89d2
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 11:51:04 2022 +0200

    Python3 wrapper: add dose* to plot()

commit e641baa
Author: Dan Dediu <[email protected]>
Date:   Mon May 30 10:52:01 2022 +0200

    Python3 wrapper: implemented medication.groups in plot()

commit a135ce3
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 19:31:06 2022 +0200

    Python3 wrapper: xlab, ylab & title added to plot()

commit 69e6575
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 12:54:08 2022 +0200

    Python3 wrapper: make col.cats in plot() work

commit be1a454
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 11:32:19 2022 +0200

    Fix bug: cex.title in plot() was not implemented

commit e1b5b65
Author: Dan Dediu <[email protected]>
Date:   Fri May 27 11:08:08 2022 +0200

    Starting to update the Python3 wrapper to reflect the new parameters

commit c2ddb1a
Author: Dan Dediu <[email protected]>
Date:   Wed May 25 17:05:02 2022 +0200

    Fix GitHub #182: the vignette shows how to change an AdhereR plot

commit b19e6bd
Author: Dan Dediu <[email protected]>
Date:   Mon May 23 22:10:25 2022 +0200

    Fixes issue #181 (plotting with aligned patients) and shows how to use AdhereR with pipe

commit 05d02b4
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 19:21:46 2022 +0200

    Latest source packages AdhereR 0.7.1 and bump to AdhereRViz 0.2.1

commit 79a966f
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 19:19:16 2022 +0200

    Work-around for GitHub #156 by allowing the plotting of the legend only

commit 9e5a311
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 12:35:57 2022 +0200

    Fix #169 by forcing arguments.that.should.not.be.defined=NULL (smartly) in sliding windows and per episodes

commit 42a3a82
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 11:59:10 2022 +0200

    Shiny: make sure the event interval defaults are correctly reset on changing the CMA

commit cf985f3
Author: Dan Dediu <[email protected]>
Date:   Thu May 19 11:51:36 2022 +0200

    Fix #179 (CMA class not correctly initialised/updated in Shiny)

commit 9348b76
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 19:19:00 2022 +0200

    Shiny UI allows plotting event intervals for sliding windows and per per episodes

    Controlled from Aesthetics -> Event intervals; default = FALSE

commit 6e28af7
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 16:22:25 2022 +0200

    AdhererViz: bump version and fix check warnings

commit e4f5d36
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 13:09:18 2022 +0200

    Fixes GitHub issue #172

commit af2443c
Author: Dan Dediu <[email protected]>
Date:   Wed May 18 13:05:10 2022 +0200

    Per episodes can also show the event intervals and gaps

commit ae58093
Author: Dan Dediu <[email protected]>
Date:   Tue May 17 14:44:20 2022 +0200

    Update documentation and fix check warnings

commit 24eb65e
Author: Dan Dediu <[email protected]>
Date:   Tue May 17 14:27:27 2022 +0200

    Plotting events and gaps seems to work for sliding windows

commit a51e0b1
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 13:25:32 2022 +0200

    Plotting intervals and gaps for sliding windows seems to work (but needs testing)

commit 95facec
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 11:14:48 2022 +0200

    ... actually, it does make sense to compute the inner.event.info even for overlapping windows (it is the user's problem to use them or not)

commit 9426ed5
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 11:06:24 2022 +0200

    Don't compute the inner.event.info if the sliding windows are overlapping

commit f3ac228
Author: Dan Dediu <[email protected]>
Date:   Fri May 13 10:22:04 2022 +0200

    Don't print inner.event.info if present for per_episode and sliding_window objects

commit f0c6a68
Author: Dan Dediu <[email protected]>
Date:   Tue Apr 5 19:57:25 2022 +0200

    Now plot() respects the order of patients given through patients.to.plot

commit f8cfb67
Author: Dan Dediu <[email protected]>
Date:   Wed Nov 24 17:31:12 2021 +0100

    GitHub #172 : initial plotting of inner event intervals

commit 049760a
Author: Dan Dediu <[email protected]>
Date:   Wed Nov 24 16:56:02 2021 +0100

    Fix GitHub #175

    + some other preliminary work on plotting event intervals in sliding windows and per intervals (but nothing user-visible yet)

commit ac22abe
Author: Dan Dediu <[email protected]>
Date:   Mon Nov 22 12:44:14 2021 +0100

    Fix GitHub #174 (plus a small bug fix when plotting as a time series with 1 point)

    Now the placeholder for partial CMAs is plotted even if they don't have one...

commit 6c9846e
Author: Dan Dediu <[email protected]>
Date:   Sun Nov 7 23:56:53 2021 +0100

    GitHub #172

    Proof-of-concept that I can return the full event.info from sliding windows -> it adds overheads so disabled by default, but can be enabled by forcing the new argument return.inner.event.info to TRUE
@mumbarkar
Copy link

mumbarkar commented Nov 1, 2022

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...

load the required libraries

library(AdhereR)
library(dplyr)

Load the built-in dataset "med.events":

df <- med.events %>% filter(PATIENT_ID %in% c(37,76))

Take a look into data

head(med.events)

Create a CMA0 object to generate patient history

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)

plot the treatment patterns

1. Create a 1 x 2 plotting matrix

par(mfrow = c(1,2))

2. create only cma0 plot

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)

3. add legends only

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

Output:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AdhereR(base) AdhereRViz enhancement (partial) work-around Not completely fixed, but a work-around is possible... suggestion Suggestion/investigation
Projects
None yet
Development

No branches or pull requests

2 participants