Skip to content

Commit

Permalink
Logo added to the same column as plot
Browse files Browse the repository at this point in the history
Also updated 'plot_venn' to work correctly in shinyApp after logo addition
  • Loading branch information
gavieira committed Nov 29, 2023
1 parent 7c5cf1e commit 7525637
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions R/06-plots_and_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ add_logo_to_plot <- function(plot,
alpha = 0.2,
width = grid::unit(100, 'pt'),
height = grid::unit(125, 'pt'),
x = grid::unit(1, 'npc'),
y = grid::unit(1, 'npc'),
x = grid::unit(0.99, 'npc'),
y = grid::unit(0.99, 'npc'),
just = c('right', 'top'),
interpolate = TRUE,
... ) {

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

# Create a new page with the specified layout
grid::grid.newpage()
Expand All @@ -48,7 +48,7 @@ add_logo_to_plot <- function(plot,
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

# Ploting logo on the right
grid::pushViewport(grid::viewport(layout.pos.col = 2))
grid::pushViewport(grid::viewport(layout.pos.col = 1))

grid::grid.raster(logo,
width = width,
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 text_size - text size of plot elements (like axes names and legend). Default: 15
#' @param ... - additional arguments passed down to [`ggplot2::geom_text`]
#'
#' @return a barplot summary of the matching results
Expand All @@ -103,11 +104,12 @@ get_uuid_list <- function(db_list) {
#' #Plotting the matching summary
#' plot_matching_summary(biblioverlap_results$summary)
#'
plot_matching_summary <- function(matching_summary_df, ...) {
plot_matching_summary <- function(matching_summary_df, 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::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))
}
Expand Down
4 changes: 2 additions & 2 deletions inst/biblioverApp/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ server <- function(input, output, session) {
output$summary_plot <- renderPlot({
summary_df <- calculate_results()$summary
summary_plot <- biblioverlap::plot_matching_summary(summary_df,
size = input$summary_value_size) +
ggplot2::theme(text=ggplot2::element_text(size= input$summary_text_size))
text_size = input$summary_text_size,
size = input$summary_value_size)
return( summary_plot )
}, height = reactive( { input$plot_height } ),
width = reactive( { input$plot_width } )
Expand Down

0 comments on commit 7525637

Please sign in to comment.