Skip to content

Commit

Permalink
add censoring limits to shiny plots
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Nov 20, 2024
1 parent 75bbd0b commit bd40935
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 9 additions & 3 deletions R/inspect-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ inspect_model <- function(mod, private) {
prior_code(input)
})
output$prior_predicted <- plotly::renderPlotly({
plotly::ggplotly(plot(prior()))
plotly::style(plotly::ggplotly(plot(prior(),
upper_censoring_limit = private$stan_input_data$upper_censoring_limit,
lower_censoring_limit = private$stan_input_data$lower_censoring_limit)), textposition = "right")
})

# model inputs
Expand Down Expand Up @@ -135,13 +137,17 @@ inspect_model <- function(mod, private) {
if (is.null(selected) || selected == "None") {
selected <- character(0)
}
plot_sero_data(data(), ncol = cols(), covariates = selected) +
plot_sero_data(data(),
ncol = cols(),
covariates = selected,
upper_censoring_limit = private$stan_input_data$upper_censoring_limit,
lower_censoring_limit = private$stan_input_data$lower_censoring_limit) +
theme(plot.margin = unit(c(1, 0, 0, 0), "cm"))
})

output$data <- plotly::renderPlotly({
if (nrow(data()) > 0) {
gp <- plotly::ggplotly(plot_inputs())
gp <- plotly::style(plotly::ggplotly(plot_inputs()), textposition="right")
if (selected_covariate() != "None") {
return(facet_strip_bigger(gp, 30))
} else {
Expand Down
8 changes: 3 additions & 5 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ plot.biokinetics_priors <- function(x,
geom_point(data = dat, size = 0.5,
aes(x = time_since_last_exp,
y = value))

plot <- add_limits(plot, upper_censoring_limit, lower_censoring_limit)
}
plot
add_limits(plot, upper_censoring_limit, lower_censoring_limit)
}

#' @title Plot serological data
Expand Down Expand Up @@ -157,7 +155,7 @@ add_limits <- function(plot, upper_censoring_limit, lower_censoring_limit) {
linetype = 'dotted') +
annotate("text", x = 1,
y = lower_censoring_limit,
label = "Lower detection limit",
label = "Lower censoring limit",
vjust = -0.5,
hjust = 0,
size = 3)
Expand All @@ -168,7 +166,7 @@ add_limits <- function(plot, upper_censoring_limit, lower_censoring_limit) {
linetype = 'dotted') +
annotate("text", x = 1,
y = upper_censoring_limit,
label = "Upper detection limit",
label = "Upper censoring limit",
vjust = -0.5,
hjust = 0,
size = 3)
Expand Down

0 comments on commit bd40935

Please sign in to comment.