Skip to content
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

Need to move shiny app additional x scale code into ssdtools ssd_plot function #106

Open
sebdalgarno opened this issue Nov 9, 2024 · 1 comment

Comments

@sebdalgarno
Copy link
Member

3 key additions required for ssd_plot prediction plot

  • ability to adjust x-axis limits
  • vertical offset of concentration estimate value
  • bold face of concentration estimate value

since new scale_x_continuous is required in app it overrides the scale created in ssd_plot

not tested well and buggy so better for functionality to live in ssdtools

@sebdalgarno
Copy link
Member Author

 gp <- ssdtools::ssd_plot(x, pred,
    left = conc, label = label, xbreaks = xbreaks, size = label_size,
    color = colour, shape = shape, hc = proportion, ci = FALSE,
    shift_x = label_adjust %>% as.numeric(),
    xlab = xaxis, ylab = yaxis, trans = trans
  ) +
    ggplot2::scale_x_continuous(
      name = xaxis, breaks = xbreaks,
      limits = c(xmin, xmax),
      labels = function(lab) {
        do.call(
          expression,
          lapply(lab, function(x) {
            mark <- label_comma(x, big.mark = big.mark)
            if (!is.na(x) & x == conc_value) {
              y <- paste0("\n", mark)
            } else {
              y <- mark
            }
            y
          })
        )
      }
    ) +
    ggplot2::scale_color_brewer(palette = palette, name = legend_colour) +
    ggplot2::scale_shape(name = legend_shape)
  
  # get breaks again for bold face as limits convert some to NA 
  actual_breaks <- gp_xbreaks(gp)
  
  gp <- 
    gp +
    ggplot2::ggtitle(title) +
    ggplot2::theme_classic() +
    ggplot2::theme(
      axis.text = ggplot2::element_text(color = "black", size = text_size),
      axis.text.x = ggplot2::element_text(face =  bold_conc(conc_value, actual_breaks)),
      axis.title = ggplot2::element_text(size = text_size),
      legend.text = ggplot2::element_text(size = text_size),
      legend.title = ggplot2::element_text(size = text_size),
    ) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants