From 7e9cb9d5cdbf6bdae1cd873801c08796300a93a8 Mon Sep 17 00:00:00 2001 From: gavieira Date: Thu, 30 Nov 2023 21:48:55 -0300 Subject: [PATCH] Added 'cowplot' dependency to convert gTree objects to ggplot --- DESCRIPTION | 1 + R/06-plots_and_app.R | 20 ++++++++++++++------ man/plot_matching_summary.Rd | 6 +++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2559d2d..45a2172 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,6 +16,7 @@ Encoding: UTF-8 LazyData: true RoxygenNote: 7.2.3 Imports: + cowplot, dplyr, ggplot2, ggVennDiagram, diff --git a/R/06-plots_and_app.R b/R/06-plots_and_app.R index b1e3bcb..0b33cb2 100644 --- a/R/06-plots_and_app.R +++ b/R/06-plots_and_app.R @@ -1,7 +1,7 @@ -#' Adding biblioverlap's logo to plots +#' Finalizing biblioverlap's plots #' #' @description -#' Helper function to add biblioverlap's logo to its plots. Except for `logo_path` and `alpha`, all its parameters are compatible with [`grid::grid.raster`]. Check its documentation for more info. +#' Helper function to finalize biblioverlap's plots. It basically adds (when `add_logo = TRUE`) the package's logo to the plot passed as argument. Except for `logo_path`, `add_logo` and `alpha`, all its parameters are compatible with [`grid::grid.raster`]. Check its documentation for more info. #' #' @param plot - plot to add logo #' @param logo_path - path to logo .png file @@ -29,7 +29,6 @@ add_logo_to_plot <- function(plot, interpolate = TRUE, ... ) { - # Set up the layout for the main plot and logo layout <- grid::grid.layout(nrow = 1, ncol = 1) # @@ -63,8 +62,16 @@ add_logo_to_plot <- function(plot, # Reset the viewport grid::popViewport(2) - return( grid::grid.grab(wrap.grobs = TRUE ) ) - #Return the combined graphical object + #Generate combined plot + combined_plot <- grid::grid.grab(wrap.grobs = TRUE ) + + #Generate final plot + final_plot <- cowplot::ggdraw() + + cowplot::draw_plot(combined_plot) + + + #Return the final graphical object + return( final_plot ) } @@ -140,7 +147,7 @@ plot_venn <- function(db_list, ...) { venn <- ggVennDiagram::ggVennDiagram(uuid, ...) + ggplot2::scale_fill_gradient(low = "#A7C7E7", high = "#08306B") + ggplot2::scale_x_continuous(expand = ggplot2::expansion(mult = .2)) - #return ( venn ) + return ( add_logo_to_plot(venn) ) } @@ -171,6 +178,7 @@ plot_upset <- function(db_list, ...) { shade.color = "steelblue", matrix.color = "#08306B", ...) + return ( add_logo_to_plot(upset) ) } diff --git a/man/plot_matching_summary.Rd b/man/plot_matching_summary.Rd index f904438..544ff06 100644 --- a/man/plot_matching_summary.Rd +++ b/man/plot_matching_summary.Rd @@ -4,13 +4,17 @@ \alias{plot_matching_summary} \title{Plotting biblioverlap's matching summary} \usage{ -plot_matching_summary(matching_summary_df, ...) +plot_matching_summary(matching_summary_df, text_size = 15, ...) } \arguments{ \item{matching_summary_df}{\itemize{ \item summary of matching process generated by \code{\link{biblioverlap}} }} +\item{text_size}{\itemize{ +\item text size of plot elements (like axes names and legend). Default: 15 +}} + \item{...}{\itemize{ \item additional arguments passed down to \code{\link[ggplot2:geom_text]{ggplot2::geom_text}} }}