Skip to content

plot function for simulation output? #151

Open

Description

@joshwlambert

Do we want to add a (S3 method) plotting function for the output from scenario_sim() to enable users to easily plot results?

I think it would be good to provide a plotting function with useful defaults and labels which outputs a ggplot object for the user to easily edit.

I'd be interested to hear thoughts on if a plot() method would be useful, if so whether we should use {ggplot2}, base R or another plotting framework (considerations of dependencies), and if there are any learnings from similar packages that provide a plot() method (e.g. {EpiNow2}).

Activity

  1. added
    question
    on Sep 15, 2025
  2. pearsonca commented on Sep 15, 2025

    @pearsonca
    Collaborator

    I'm generally skeptical of pulling in more dependencies, but I do think it's useful to provide users a standard-ish way to have this sort of capability.

    Could be done with vignette snippet? Maybe something in inst? Also possible with an extension package, but that's a bit unwieldy for both users and dev.

    I think vignette is best - would also show the interior code where people might want a specialized tweak.

  3. joshwlambert commented on Jan 26, 2026

    @joshwlambert
    CollaboratorAuthor

    This is partially (or potentially fully) addressed by the changes in PR #201 which adds plotting code chunks. The vignette uses {tinyplot} which is a dependency-free (only depends on packages that are shipped with R, e.g. {grDevices}) package and has a nice user-interface.

    If the main concern for providing a plotting method for scenario_sim() is the extra dependencies {ggplot2} would pull in, then {tinyplot} could be a good alternative. The downside is that it does not allow users to edit with layers in the same (and familiar) way.

  4. pearsonca commented on Jan 26, 2026

    @pearsonca
    Collaborator

    I think the vignette snippet provides a sufficient minimal solution. Would be nice to add a ggplot2 chunk in approximately the same place (for people who prefer minimal dependencies vs the common demand for nice extras).

    Also worth revising the scenario_sim() docs to point to the vignettes as a place where people can grab standard-ish, reusable plotting code.

  5. joshwlambert commented on Jan 27, 2026

    @joshwlambert
    CollaboratorAuthor

    Would be nice to add a ggplot2 chunk in approximately the same place (for people who prefer minimal dependencies vs the common demand for nice extras).

    Okay, my proposed solution is: keep the current vignettes with only {tinyplot} for the CRAN/default version, and then use pkgdown::in_pkgdown() to determine when the vignettes are being rendered for the website and add a tabset with a tab containing the equivalent plotting code with {ggplot2}.

    The reason for this is that it would avoid adding {ggplot2} to Imports or Suggests and can instead be added to Config/Needs in the DESCRIPTION file or directly into pkgdown.yaml r-lib/actions/setup-r-dependencies@v2. On the other hand {ggplot2} would only need to go into Suggests, so it wouldn't be tightly coupled, but I feel that the suggested dependencies are often installed (e.g. during CI runs) so keeping it only for the website keeps things more lightweight.

    Also IIRC the tabsetting doesn't render on CRAN vignettes.

  6. joshwlambert commented on Jun 15, 2026

    @joshwlambert
    CollaboratorAuthor

    Looking to close this issue. My preferred solution to this issue is to create a companion package (e.g. {VisRingbp} or {ringbp.plot}). Mainly because {ringbp} is used in {propose} which contains plotting code, so it's probably good to have that plotting code separated out, documented, tested and usable by others, independent of {propose}.

  7. pearsonca commented on Jun 15, 2026

    @pearsonca
    Collaborator

    reasonable suggestion; even if you do decide to show some plotting in vignettes, makes that work still easier if there's another package that just does good pre-sets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions