Skip to content

Commit

Permalink
Added a flag allowing users to remove the logo from plots
Browse files Browse the repository at this point in the history
  • Loading branch information
gavieira committed Dec 16, 2023
1 parent 670edba commit bdb1c25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 19 additions & 7 deletions R/06-plots_and_app.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Finalizing biblioverlap's plots
#' Adding logo biblioverlap's plots
#'
#' @description
#' 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.
#' Helper function to finalize biblioverlap's plots. It basically adds the package's logo to the plot passed as argument. Except for `logo_path` 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
Expand Down Expand Up @@ -86,6 +86,7 @@ get_uuid_list <- function(db_list) {
#' Plotting biblioverlap's matching summary
#'
#' @param matching_summary_df - summary of matching process generated by [`biblioverlap`]
#' @param add_logo - boolean specifying whether to add package logo to plot or not. Default: TRUE
#' @param text_size - text size of plot elements (like axes names and legend). Default: 15
#' @param ... - additional arguments passed down to [`ggplot2::geom_text`]
#'
Expand All @@ -104,20 +105,25 @@ get_uuid_list <- function(db_list) {
#' #Plotting the matching summary
#' plot_matching_summary(biblioverlap_results$summary)
#'
plot_matching_summary <- function(matching_summary_df, text_size = 15, ...) {
plot_matching_summary <- function(matching_summary_df, add_logo = TRUE, text_size = 15, ...) {
summary_plot <- matching_summary_df %>%
ggplot2::ggplot(ggplot2::aes(x = .data$category, y = .data$n_docs, fill = .data$doc_subset)) +
ggplot2::geom_bar(stat = 'identity', position = 'stack') +
ggplot2::geom_text(ggplot2::aes(label = paste0(.data$n_docs," (",.data$perc_inside_category,"%)")), position = ggplot2::position_stack(vjust = 0.5), ... ) +
ggplot2::theme(text=ggplot2::element_text(size= text_size))

return(add_logo_to_plot(summary_plot))
if (add_logo) {
return(add_logo_to_plot(summary_plot))
}

return(summary_plot)
}


#' Plotting Venn Diagram from biblioverlap results
#'
#' @param db_list - list of matched dataframes (with UUID column added by [`biblioverlap`])
#' @param add_logo - boolean specifying whether to add package logo to plot or not. Default: TRUE
#' @param ... - Additional arguments that can be passed down to [`ggVennDiagram::ggVennDiagram`]
#'
#' @return a Venn Diagram representation of document overlap between the input datasets
Expand All @@ -133,18 +139,23 @@ plot_matching_summary <- function(matching_summary_df, text_size = 15, ...) {
#' #Plotting the Venn diagram
#' plot_venn(biblioverlap_results$db_list)
#'
plot_venn <- function(db_list, ...) {
plot_venn <- function(db_list, add_logo = TRUE, ...) {
uuid <- get_uuid_list(db_list)
venn <- ggVennDiagram::ggVennDiagram(uuid, ...) +
ggplot2::scale_fill_gradient(low = "#A7C7E7", high = "#08306B") +
ggplot2::scale_x_continuous(expand = ggplot2::expansion(mult = .2))

return ( add_logo_to_plot(venn) )
if (add_logo) {
return(add_logo_to_plot(venn))
}

return ( venn )
}

#' Plotting UpSet plot from biblioverlap results
#'
#' @param db_list - list of matched dataframes (with UUID column added by [`biblioverlap`])
#' @param add_logo - boolean specifying whether to add package logo to plot or not. Default: TRUE
#' @param ... - arguments to be passed down to [`UpSetR::upset`]
#'
#' @return a UpSet plot representation of document overlap between the input datasets
Expand All @@ -160,7 +171,7 @@ plot_venn <- function(db_list, ...) {
#' #Plotting the UpSet plot
#' plot_upset(biblioverlap_results$db_list)
#'
plot_upset <- function(db_list, ...) {
plot_upset <- function(db_list, add_logo = TRUE, ...) {
uuid <- get_uuid_list(db_list)
upset <- UpSetR::upset(UpSetR::fromList(uuid),
main.bar.color = "#08306B",
Expand All @@ -171,6 +182,7 @@ plot_upset <- function(db_list, ...) {
...)

return ( add_logo_to_plot(upset) )
#return ( upset )
}


Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Why is such a quick update needed? Please explain. Please also re-read
the CRAN policies about submission frequency.

This was entirely my fault, sorry. The fixes on my last submission were actually pretty small, so the update was not necessary at all. It's my first package and I had forgotten about submission frequency policies. Rest assured that it won't happen again and thanks for your time!
This was entirely my fault, sorry. The fixes since my last submission were actually pretty small, so the update was not necessary at all. It's my first package and I had forgotten about submission frequency policies. Rest assured that it won't happen again and thanks for your time!

### Fourth submission (Version 1.0.3)

Expand Down
2 changes: 1 addition & 1 deletion data-raw/data_prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ library(ggplot2)
test_data = list(A = 1:1, B = 1:1, C = 1:1, D = 1:1)

p <- ggVennDiagram(test_data, label_size = 15,
set_size = 15, label_alpha = 1) +
set_size = 15, label_alpha = 0) +
scale_color_manual(values = rep("black", 4))

#Names to be plotted instead of intersection counts
Expand Down

0 comments on commit bdb1c25

Please sign in to comment.