n-kall / priorsense

priorsense: an R package for prior diagnostics and sensitivity
https://n-kall.github.io/priorsense/
GNU General Public License v3.0
53 stars 5 forks source link

Issue with `powerscale_summary_plot` when `powerscale_plot_quantities` is called with `msce = TRUE` #9

Closed fraupflaume closed 1 year ago

fraupflaume commented 1 year ago

Through a Stack Overflow question, I discovered this package. Looks great! The question wasn't specifically related to this package, but the answer is. (Unless I'm completely daft...which, ya, that's definitely possible.)

The questioner was essentially asking why their user-defined function wasn't working. This function included powerscale_plot_quantities. The issue only occurs when you set mcse = TRUE.

Currently, the plot calls all use aes_strings, which is deprecated. However, this only generates a warning. I'm not sure why strings are called, either. (All of these could be changed to aes after removing the quotes.) The issue lies in the last bit of code in powerscale_summary_plot (called by powerscale_plot_quantities).

p <- p + ggplot2::scale_linetype_manual(values = "dashed", name = NULL) + 
  ggplot2::geom_hline(ggplot2::aes_string(yintercept = "mcse_min", 
                                          linetype = "+/-2MCSE"), 
                      data = base_mcse, color = "black") + 
  ggplot2::geom_hline(ggplot2::aes_string(yintercept = "mcse_max", 
                                          linetype = "+/-2MCSE"), 
                      data = base_mcse, color = "black")

The use of linetype here sets the name shown in the legend. However, when aes_strings is used, this name is interpreted as symbolic. Since there is no variable with this name in the data, it renders an error. The following code fixes the issue created here.

p <- p + ggplot2::geom_hline(ggplot2::aes(yintercept = mcse_min,
                                          linetype = "+/-2MCSE"),
                             data = base_mcse, color = "black") + 
  ggplot2::geom_hline(ggplot2::aes(yintercept = mcse_max, 
                                   linetype = "+/-2MCSE"), 
                      data = base_mcse, color = "black")
n-kall commented 1 year ago

Thanks for reporting this! I'll fix it shortly :)