Skip to content

plot function that shows all levels of the hierarchy #34

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

Open
aghaynes opened this issue Nov 1, 2021 · 0 comments
Open

plot function that shows all levels of the hierarchy #34

aghaynes opened this issue Nov 1, 2021 · 0 comments

Comments

@aghaynes
Copy link
Member

aghaynes commented Nov 1, 2021

Is your feature request related to a problem? Please describe.
Useful to have all info in one plot

grafik

Describe the solution you'd like

Describe alternatives you've considered
manual

Additional context

Something like this...

Probably needs an lapply rather than the first three subsets. And some way to define what level to use...

bubblekpiplot <- function(kpis = kpis, kpi, title, lkup){
  bubbledat <- kpis %>%
    `[[`(., kpi) %>%
    `[[`(., "lowest_level") %>%
    `[[`(., "calc") %>%
    left_join(lkup)
  rowdat<- kpis %>%
    `[[`(., kpi) %>%
    `[[`(., "upper_level") %>%
    `[[`(., "calc")
  overall <- kpis %>%
    `[[`(., kpi) %>%
    `[[`(., "overall") %>%
    `[[`(., "calc")
  bubbledat %>%
    ggplot(aes(x = stat, y = upper_level, size = N, pch = "Site")) +
    geom_vline(aes(xintercept = stat), data = overall, lty = 2, col = "grey") +
    geom_point(aes(x = stat, y = upper_level,
               pch = "Level"),
               data = rowdat,
               inherit.aes = FALSE,
               # size = 2
               ) +
    geom_point(col = unibeRed(.5)) +
    myggtheme() +
    # xlim(0,100) +
    scale_y_discrete(limits=rev) +
    ggtitle(title) +
    guides(size = guide_legend(title = "N participants in site",
                               fill = NA,
                               order = 2,
                               nrow = 1),
           shape = guide_legend(order = 1, col = "black")) +
    theme(plot.title.position = "plot",
          axis.title.x = element_blank()) +
    scale_shape_manual(values = c(Site = 1, Country = 3),
                       name = "",
                       guide = guide_legend(override.aes = list(col = c("black", unibeRed(.5)),
                                                                size = 2))) +
    scale_size_continuous(guide = guide_legend(nrow = 1,
                                               override.aes = list(fill = NA),
                                               fill = NA)) +
    labs(caption = "The dashed vertical line represents the trial as a whole")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant