Created
October 9, 2011 21:38
-
-
Save mages/1274229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Continue from the above R code | |
year.start.pos <- regexpr("year =", bibfile, perl=TRUE) | |
year.lines <- which( year.start.pos > 0 ) | |
year.split <- strsplit(bib[year.lines], "[ =,]", perl=TRUE) | |
Pub.year <- as.numeric(sapply(year.split, "[[", 6)) | |
tradPub <- as.data.frame(table(Pub.year)) | |
names(tradPub) <- c("year", "traditional paper") | |
## Get information about the online published PDF files | |
library(XML) | |
webPub <- | |
readHTMLTable(readLines("http://cran.r-project.org/doc/contrib/"))[[1]] | |
## look only at the PDF files | |
pdfs <- regexpr(".pdf", as.character(webPub[,2])) | |
webPub.modified <- webPub[pdfs > 0, 3] | |
webPub.modified <- strsplit(na.omit(as.character(webPub.modified)), "[ -]") | |
webPub.year <- as.numeric(sapply(webPub.modified, "[[", 3)) | |
webPub <- as.data.frame(table(webPub.year)) | |
names(webPub) <- c("year", "online PDF") | |
## Merge information about the online and traditional books | |
totalPub <- merge(tradPub, webPub, all=TRUE) | |
totalPub[is.na(totalPub)] <- 0 | |
## Calculate the cumulative statistics | |
cumPub <- data.frame(year=totalPub$year, apply(totalPub[,2:3], 2, cumsum )) | |
names(cumPub) <- c("year", "traditional paper", | |
"online PDF") | |
## We use the googleVis package to create area charts | |
library(googleVis) | |
cumPlot <- gvisAreaChart(cumPub, "year", | |
options=list(title="Number of R related books available", | |
isStacked=TRUE)) | |
incPlot <- gvisAreaChart(totalPub, "year", | |
options=list(title="Number of R | |
related books published", | |
isStacked=FALSE)) | |
inccumPlot <- gvisMerge(incPlot, cumPlot) | |
plot(inccumPlot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment