Skip to content

Commit

Permalink
Create a new .R file to plot figures for the paper
Browse files Browse the repository at this point in the history
  • Loading branch information
gavieira committed Dec 28, 2023
1 parent 567989a commit c37d0d9
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 43 deletions.
43 changes: 0 additions & 43 deletions data-raw/data_prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,3 @@ ufrj_bio_0122 <- lapply(df_list, function(df) {

#Saving as package data
usethis::use_data(ufrj_bio_0122, compress = 'xz')



#Generating a venn diagram that show the intersects calculated in each round of pairwise comparisons (at first, this image will only be displayed in the paper)

#Source: https://stackoverflow.com/questions/72651478/how-do-i-make-certain-regions-of-of-my-venn-diagram-colored-and-have-the-rest-bl

library(ggVennDiagram)
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 = 0) +
scale_color_manual(values = rep("black", 4))

#Names to be plotted instead of intersection counts
new_names <-c('A', 'B', 'C', 'D',
'AB', 'AC', 'AD', 'BC', 'BD', 'CD',
'ABC', 'ABD', 'ACD', 'BCD',
'ABCD')

p$layers[[1]]$mapping <- aes(fill = name) #Each name (intersection) can have an associated color now
p$layers[[4]]$data$both <- new_names #Changing 'both' data column to have the intersect names, which will then be plotted instead


p + scale_fill_manual(values = c(A = 'red',
A..B = 'red',
A..C = 'red',
A..D = 'red',
A..B..C = 'red',
A..B..D = 'red',
A..C..D = 'red',
A..B..C..D = 'red',
B = 'blue',
B..C = 'blue',
B..D = 'blue',
B..C..D = 'blue',
C = 'darkgreen',
C..D = 'darkgreen',
D = 'darkgreen'
) ) + #Specifying a color for each intersect
theme(legend.position = '') #removing legend
97 changes: 97 additions & 0 deletions data-raw/paper_figs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
############## Figures for the biblioverlap paper ###################

library(ggVennDiagram) #Need to load ggVennDiagram first because it masks `plot_venn` and `plot_upset` functions from biblioverlap
library(biblioverlap)
library(dplyr)
library(ggplot2)
library(patchwork)

################ Running biblioverlap for example dataset ################
results <- biblioverlap(ufrj_bio_0122)
db_list <- results$db_list


################ Getting biblioverlap's plots ###########################
plot_matching_summary(results$summary, add_logo = FALSE)
plot_venn(db_list, add_logo = FALSE) #gets masked when loading ggVennDiagram alongside biblioverlap
plot_upset(db_list, add_logo = FALSE) #gets masked when loading ggVennDiagram alongside biblioverlap


############### Generating a venn diagram that show the intersects calculated in each round of pairwise comparisons ###########################
#Source: https://stackoverflow.com/questions/72651478/how-do-i-make-certain-regions-of-of-my-venn-diagram-colored-and-have-the-rest-bl

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 = 0) +
scale_color_manual(values = rep("black", 4))

#Names to be plotted instead of intersection counts
new_names <-c('A', 'B', 'C', 'D',
'AB', 'AC', 'AD', 'BC', 'BD', 'CD',
'ABC', 'ABD', 'ACD', 'BCD',
'ABCD')

p$layers[[1]]$mapping <- aes(fill = name) #Each name (intersection) can have an associated color now
p$layers[[4]]$data$both <- new_names #Changing 'both' data column to have the intersect names, which will then be plotted instead


p + scale_fill_manual(values = c(A = 'red',
A..B = 'red',
A..C = 'red',
A..D = 'red',
A..B..C = 'red',
A..B..D = 'red',
A..C..D = 'red',
A..B..C..D = 'red',
B = 'blue',
B..C = 'blue',
B..D = 'blue',
B..C..D = 'blue',
C = 'darkgreen',
C..D = 'darkgreen',
D = 'darkgreen'
) ) + #Specifying a color for each intersect
theme(legend.position = '') #removing legend


########### Generating venn diagrams for subsets of the data ##################

#Open access docs
open_access_docs <- lapply(db_list, function(db) {
filter(db, !(`Open Access Colour` %in% c('', 'unknown')))
})
open_access <- plot_venn(open_access_docs, add_logo = FALSE, label = c("count")) +
labs(title = 'Open Access') +
theme(plot.title = element_text(size = 15, hjust = 0.5),
legend.position = 'none')

#Closed access docs
closed_access_docs <- lapply(db_list, function(db) {
filter(db, `Open Access Colour` == '')
})
closed_access <- plot_venn(closed_access_docs, add_logo = FALSE, label = c("count")) +
labs(title = 'Closed Access') +
theme(plot.title = element_text(size = 15, hjust = 0.5),
legend.position = 'none')

#Docs 10 or more citações
i10_docs <- lapply(db_list, function(db) {
filter(db, `Citing Works Count` >= 10)
})
i10 <- plot_venn(i10_docs, add_logo = FALSE, label = c("count")) +
labs(title = '10 or more citations') +
theme(plot.title = element_text(size = 15, hjust = 0.5),
legend.position = 'none')

#Preprints
preprint_docs <- lapply(db_list, function(db) {
filter(db, `Publication Type` == 'preprint')
})
preprints <- plot_venn(preprint_docs, add_logo = FALSE, label = c("count")) +
labs(title = 'Preprints') +
theme(plot.title = element_text(size = 15, hjust = 0.5),
legend.position = 'none')


open_access + closed_access + i10 + preprints + plot_annotation(tag_levels = 'A')

0 comments on commit c37d0d9

Please sign in to comment.