Skip to content

Commit

Permalink
Add facet and colour options to compared lsc
Browse files Browse the repository at this point in the history
  • Loading branch information
Marta Alcalde-Herraiz committed Nov 15, 2024
1 parent 40c2bc1 commit dd56b21
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
32 changes: 24 additions & 8 deletions inst/shiny/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,50 @@ if(file.exists(file.path(getwd(), "data", "appData.RData"))){
source(file.path(getwd(),"scripts", "preprocess.R"))
}

plotComparedLsc <- function(lsc, cohorts, colour = NULL){
plotComparedLsc <- function(lsc, cohorts, colour = NULL, facet = NULL){
lsc <- lsc |> tidy()
plot_data <- lsc |>
filter(cohort_name %in% c(cohorts
)) |>
select(cohort_name,
select(database = cdm_name,
cohort_name,
variable_name,
variable_level,
time_window = variable_level,
concept_id,
table_name,
table = table_name,
percentage) |>
pivot_wider(names_from = cohort_name,
values_from = percentage)


# plot <- visOmopResults::scatterPlot(plot_data,
# x = cohorts[1],
# y = cohorts[2],
# colour = colour,
# facet = facet,
# line = FALSE,
# point = TRUE,
# ribbon = FALSE) +
# ggplot2::geom_abline(slope = 1, intercept = 0, color = "red", linetype = "dashed") +
# ggplot2::theme_bw()

plot <- plot_data |>
ggplot(aes(text = paste("Concept:", variable_name,
"<br>Concept ID:", concept_id,
"<br>Time window:", variable_level,
"<br>Table:", table_name,
"<br>Time window:", time_window,
"<br>Table:", table,
"<br>Cohorts: "))) +
geom_point(aes(x = !!sym(cohorts[1]),
y = !!sym(cohorts[2]),
colour = !!sym(colour))) +
colour = !!sym(colour))
) +
geom_abline(slope = 1, intercept = 0,
color = "red", linetype = "dashed") +
theme_bw()

if(!is.null(facet)){
plot <- plot +
ggplot2::facet_wrap(facet)
}
ggplotly(plot)

}
4 changes: 3 additions & 1 deletion inst/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,9 @@ server <- function(input, output, session) {
plotComparedLsc(lsc = outputLSC(),
cohorts = c(input$compare_large_scale_characteristics_grouping_cohort_1,
input$compare_large_scale_characteristics_grouping_cohort_2),
colour = "table_name")
colour = c(input$compare_large_scale_characteristics_colour_1),
facet = c(input$compare_large_scale_characteristics_facet_1)
)
})

# orphan -----
Expand Down
23 changes: 23 additions & 0 deletions inst/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,28 @@ ui <- bslib::page_navbar(
title = "Plot",
bslib::card(
full_screen = TRUE,
bslib::layout_sidebar(
sidebar = bslib::sidebar(width = 400, open = "closed",
shinyWidgets::pickerInput(
inputId = "compare_large_scale_characteristics_colour_1",
label = "Colour",
selected = c("table"),
multiple = TRUE,
choices = c("table", "database", "time_window"),
options = list(`actions-box` = TRUE, size = 10, `selected-text-format` = "count > 3")
),
shinyWidgets::pickerInput(
inputId = "compare_large_scale_characteristics_facet_1",
label = "Facet",
selected = c("database"),
multiple = TRUE,
choices = c("table", "database", "time_window"),
options = list(`actions-box` = TRUE, size = 10, `selected-text-format` = "count > 3")
),
position = "right"
),
position = "right"
),
plotly::plotlyOutput("plotly_compare_lsc") |> withSpinner()
)
)
Expand Down Expand Up @@ -797,6 +819,7 @@ ui <- bslib::page_navbar(
)
)
),
# Cohort overlap ----
bslib::nav_panel(
title = "Plot cohort overlap",
bslib::card(
Expand Down

0 comments on commit dd56b21

Please sign in to comment.