Skip to content
Snippets Groups Projects
Select Git revision
  • 78bb8521f0e1c6c59af23a5bb04ffd3e199cb671
  • master default protected
  • v2.1.1
  • v2.1.0
4 results

identityplot.R

Blame
  • identityplot.R 1.25 KiB
    # WARNING - Generated by {fusen} from /dev/flat_full.Rmd: do not edit by hand
    
    
    #' Generate an identity plot
    #'
    #' This function generates an identity plot for comparing actual values with estimates.
    #'
    #' @param comparison_df A data frame containing comparison results with "actual" and "estimate" columns.
    #' @param ... additional parameters to pass ggplot2::aes 
    #' @return A ggplot2 identity plot.
    #'
    #' @importFrom ggplot2 sym aes geom_point geom_abline facet_wrap theme_bw ggtitle scale_x_log10 scale_y_log10
    #' @export
    #' @examples
    #'   comparison_data <- data.frame(
    #'    actual = c(1, 2, 3, 4, 5),
    #'    estimate = c(0.9, 2.2, 2.8, 4.1, 5.2),
    #'    description = rep("Category A", 5))
    #' identity_plot(comparison_data)
    
    identity_plot <- function(comparison_df, ...){
      
      args <- lapply(list(...), function(x) if (!is.null(x)) ggplot2::sym(x))
    
      
      ggplot2::ggplot(comparison_df) +
        ggplot2::geom_point(ggplot2::aes(x = actual, y = estimate, !!!args), alpha = 0.6, size = 2)  +
        ggplot2::geom_abline(intercept = 0, slope = 1, lty = 3, col = 'red', linewidth = 1) +
        ggplot2::facet_wrap(~description, scales = "free") +
        ggplot2::theme_bw()  +
        ggplot2::ggtitle("Identity plot") #+
        #ggplot2::scale_x_log10() +
        #ggplot2::scale_y_log10()
        
    
    }