R/plot_mids_results.R

Defines functions plot_mids_results

Documented in plot_mids_results

plot_mids_results <-
  function(data_for_plotting, title, plot_name, path, ...) {

    # Transform exposure into factor (to be able to order plot axis by exosure Family name)
    data_for_plotting <- data_for_plotting %>%
      mutate(exp_lev = factor(Exposure, levels = Exposure),
             Exposure = factor(exp_lev, levels = rev(levels(exp_lev))))

    # Change order of the variables to add SumDEHP after its compounds
    data_for_plotting <- data_for_plotting[c(1:47, 53, 48:52), ]

    # Plot data
    plot <-
      ggplot2::ggplot(data_for_plotting, aes(Estimate, Exposure)) +
      geom_point(color = "#56B4E9") +
      geom_errorbarh(aes(xmin = conf_low, xmax = conf_high), color = "#56B4E9", height = 0.1) +
      geom_vline(xintercept = 1, linetype = "dashed", color = "gray") +
      xlab("IRR") +
      xlim(...) +
      ylab("") +
      theme_bw() +
      ggtitle(title) +
      theme(text = element_text(size = 16), axis.text.x = element_text(size = 12), axis.text.y = element_text(size = 12), plot.title = element_text(face = "bold"), legend.position = "none")

    #save the plot to a file
    ggplot2::ggsave(plot_name, plot = last_plot(), path = path, device = "jpeg", scale = 1, width = 20, height = 18, units = "cm", dpi = 150, limitsize = TRUE)

    return(plot)
  }
groovearmada/exwas documentation built on May 29, 2019, 12:02 a.m.