Skip to content

Commit

Permalink
Cleaned add_logo_to_plot function
Browse files Browse the repository at this point in the history
All viewport-related function calls and the like were really not necessary after all
  • Loading branch information
gavieira committed Dec 1, 2023
1 parent 4ffa1c4 commit 1c0b756
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions R/06-plots_and_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,13 @@ add_logo_to_plot <- function(plot,
# Set up null graphics device to avoid unintentional plotting
grDevices::pdf(NULL)

# Set up the layout for the main plot and logo
layout <- grid::grid.layout(nrow = 1, ncol = 1)

## Create a new page with the specified layout
grid::grid.newpage()
grid::pushViewport(grid::viewport(layout = layout))

## Plot the Venn diagram on the left
grid::pushViewport(grid::viewport(layout.pos.col = 1))
print(plot, newpage = FALSE)

## Clear the viewport before adding the logo
grid::popViewport(1)
# Printing plot
print(plot)

# Getting logo
logo_raw <- png::readPNG(logo_path) #Importing logo into R
logo <- matrix(grDevices::rgb(logo_raw[,,1],logo_raw[,,2],logo_raw[,,3], logo_raw[,,4] * alpha), nrow=dim(logo_raw)[1]) #Adding transparency to logo - source: https://stackoverflow.com/questions/11357926/r-add-alpha-value-to-png-image

# Pushing viewport
grid::pushViewport(grid::viewport(layout.pos.col = 1))
# Ploting logo
grid::grid.raster(logo,
width = width,
Expand All @@ -65,9 +52,6 @@ add_logo_to_plot <- function(plot,
interpolate = interpolate,
...)

# Reset the viewport
grid::popViewport(2)

#Generate combined plot
combined_plot <- grid::grid.grab(wrap.grobs = TRUE )

Expand All @@ -84,7 +68,6 @@ add_logo_to_plot <- function(plot,




#' Extracting list of uuid columns from biblioverlap results
#'
#' @description
Expand Down

0 comments on commit 1c0b756

Please sign in to comment.