Skip to content

Instantly share code, notes, and snippets.

@mfenner
Created September 22, 2013 18:06
Show Gist options
  • Save mfenner/6662304 to your computer and use it in GitHub Desktop.
Save mfenner/6662304 to your computer and use it in GitHub Desktop.
Create VennDiagram using ALM data
#' Venn diagram F1000 vs. Wikipedia for PLOS ALM
#'
#' @author Martin Fenner <[email protected]>
# Read in required functions
library("plyr")
library(VennDiagram)
# Options
report_date <- "2013-09-11"
report_name <- "example"
# Get ALM for these articles by merging them with last monthly report
alm <- read.csv("some_alm_data.csv", header=TRUE)
alm <- na.omit(alm)
reassignWikipedia<- function(x) if (x > 0) 1 else 0
alm$wikipedia_bin <- aaply(alm$wikipedia, 1, reassignWikipedia)
reassignF1000 <- function(x) if (x > 0) 2 else 0
alm$f1000_bin <- aaply(alm$f1000, 1, reassignF1000)
alm$article_group = alm$wikipedia_bin + alm$f1000_bin
reassignCombined <- function(x) if (x == 3) 1 else 0
alm$combined_bin <- aaply(alm$article_group, 1, reassignCombined)
reassignNo <- function(x) if (x == 0) 1 else 0
alm$no_bin <- aaply(alm$article_group, 1, reassignNo)
# Remember to devide f1000_bin by 2, as this is the default value
summary <- colSums(subset(alm, select=c("wikipedia_bin","f1000_bin","combined_bin","no_bin")), na.rm=TRUE)
rows <- nrow(alm)
# Options
plos.start_date <- NA
plos.end_date <- NA
plos.colors <- c("#c9c9c7","#0000ff","#ff0000")
plos.title <- "Selecting PLOS Papers"
plos.description <- c("Number of PLOS articles that have been recommended by F1000Prime (red) and/or mentioned in Wikipedia (blue).")
# Plot the chart.
plos.pdf <- paste(venndiagram", "_", report_name, "_", report_date, ".pdf", sep="")
pdf(file=plos.pdf, width=11, height=8.5, useDingbats=FALSE)
opar <- par(mai=c(0.5,.75,3.5,0.5), omi=c(0.5,0.5,1.5,0.5), mgp=c(3,.5,.5), fg="black", cex.main=2, cex.lab=1.5, col=plos.color, col.main=plos.color, col.lab=plos.color, xaxs="i", yaxs="i")
plot.new()
title(main=plos.title, cex.main=2, outer=TRUE, line=4, adj=0)
mtext(paste(strwrap(plos.description,width=90), collapse="\n"), side=3, col="black", outer=TRUE, line=1.5, adj=0)
pushViewport(viewport(x=0.5, y=7, w=6, h=6, default.units = "inches", just=c("left", "top")))
venn.plot <- draw.triple.venn(area1=rows,area2=summary[1],area3=summary[2]/2,n12=summary[1],n23=summary[3],n13=summary[2]/2,n123=summary[3],euler.d=TRUE,scaled=TRUE,fill=plos.colors,cex=2,fontfamily = rep("sans", 7))
popViewport()
par(opar)
dev.off()
@sckott
Copy link

sckott commented Sep 22, 2013

@mfenner, where does the some_alm_data.csv file come from? I was hoping to understand the whole wofklow from searching for data to plotting. Is some_alm_data.csv just a csv file written after a call to alm() function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment