From ae24fd1ba84498bc81f2cfd0da414eb3c52ea931 Mon Sep 17 00:00:00 2001 From: Xiao Yan Date: Mon, 21 Oct 2024 20:58:28 -0400 Subject: [PATCH] Update plot_est_box Updated plot_est_box to adjust text --- R/plot_est_box.R | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/R/plot_est_box.R b/R/plot_est_box.R index 3dae974..b4d489a 100644 --- a/R/plot_est_box.R +++ b/R/plot_est_box.R @@ -60,17 +60,14 @@ plot_est_box <- function(input, ...) { UpperCI = upperbd ) - # Alternate label positions to avoid overlap - label_position <- rep(c(1, -1), length.out = nrow(plot_data)) - # ggplot2 visualization ggplot2::ggplot(plot_data, ggplot2::aes(x = Treatment, y = Mean)) + ggplot2::geom_point(size = 3) + ggplot2::geom_errorbar(ggplot2::aes(ymin = LowerCI, ymax = UpperCI), width = 0.2, color = "blue") + ggplot2::labs(title = "Treatment Effect Estimates", x = "Treatment Level", y = "Effect") + ggplot2::theme_minimal() + - ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.2 * label_position, label = paste0("Mean: ", round(Mean, 2))), vjust = -0.5) + - ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.4 * label_position, label = paste0("95% CI: [", round(LowerCI, 2), ", ", round(UpperCI, 2), "]")), vjust = -0.5) + + ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.05, label = paste0("Mean: ", round(Mean, 2))), vjust = -0.5) + + ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.50, label = paste0("95% CI: [", round(LowerCI, 2), ", ", round(UpperCI, 2), "]")), vjust = -0.5) + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1)) + - ggplot2::expand_limits(y = max(plot_data$UpperCI) + 0.5) + ggplot2::expand_limits(y = max(plot_data$UpperCI) + 0.15) }