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

Summarised bubble plots fail when stat function requires additional arguments #20

Open
PuzzledFace opened this issue Jan 16, 2023 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@PuzzledFace
Copy link
Collaborator

For example:

testProp %>%
  createQtlBubblePlot(
    x=Snapshot,
    y=proportion,
    summarise=TRUE,
    stat=weighted.mean,
    w=n_patients,
    group=COUNTRY,
    size=n_patients,
    limits = list(
      list(label = "QTL (12%)", colour = "red", type = "dashed", y = 0.12, x = 1.5, vjust = -1),
      list(label = "Sec Lim (8%)", colour = "goldenrod", type = "dotted", y = 0.08, x = 3, vjust = -0.5)
    ),
    boxLeft = -2,
    boxRight = 4
  ) +
  guides(colour=guide_legend(ncol=2)) +
  coord_cartesian(xlim=c(-4, 6))
#> Error in `dplyr::summarise()`:
#> ! Problem while computing `proportion = stat(proportion, ...)`.
#> ℹ The error occurred in group 1: COUNTRY = "AUS", Snapshot = "2022-11-25".
#> Caused by error in `weighted.mean.default()`:
#> ! object 'n_patients' not found

This appears to be because weighted.average does not data-mask its arguments.

  • The simplest solution is to preprocess the input dataset first [see below], but a workaround would be helpful.
  • How to spot that this problem might arise during input validation?
  group_by(COUNTRY, Snapshot) %>% 
  summarise(
    proportion=weighted.mean(proportion, w=n_patients),
    n_patients=sum(n_patients),
    .groups="drop"
  ) %>% 
  createQtlBubblePlot(
    x=Snapshot,
    y=proportion,
    group=COUNTRY,
    size=n_patients,
    limits = list(
      list(label = "QTL (12%)", colour = "red", type = "dashed", y = 0.12, x = 1.5, vjust = -1),
      list(label = "Sec Lim (8%)", colour = "goldenrod", type = "dotted", y = 0.08, x = 3, vjust = -0.5)
    ),
    boxLeft = -2,
    boxRight = 4
  ) +
  guides(colour=guide_legend(ncol=2)) +
  coord_cartesian(xlim=c(-4, 6))

works as expected.

@PuzzledFace PuzzledFace added bug Something isn't working enhancement New feature or request labels Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant