Last active
August 29, 2015 14:24
-
-
Save njahn82/82a062847398ca8f2627 to your computer and use it in GitHub Desktop.
fetch_openaire.r
This file contains hidden or 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
require(ropenaire) | |
require(dplyr) | |
# fetch ugoe projects | |
ugoe <- roa_projects(org = "UGOE") | |
# fetch publications | |
tt <- plyr::ldply(as.character(ugoe$grantID), roa_pubs) | |
# tidy up: split collapsed ec projects | |
tmp <- | |
tidyr::separate( | |
tt, Project.Name..GA.Number., into = c("grant_1", "grant_2", "grant_3", "grant_4"), | |
sep = ", ", extra = "merge" | |
) | |
test <- reshape2::melt(tmp, id.vars = c("Access"), | |
c("grant_1","grant_2","grant_3","grant_4")) | |
# grep ugoe projects | |
testa <- | |
lapply(ugoe$acronym, function(x) | |
test[grep(x, test$value),]) %>% rbind_all | |
# prepare merging | |
testa$grant_id <- stringr::str_extract(testa$value, "[:digit:]+") | |
# tabulate publications for each project and access level | |
ugoe_table <- data.frame(table(testa$grant_id, testa$Access)) | |
# merge with project list to receive more infos | |
my_df <- | |
merge(ugoe, ugoe_table, by.x = "grantID", by.y = "Var1", all.x = T) | |
# table | |
tt_table <- | |
reshape::cast(my_df, grantID + acronym + title + startdate + enddate + ecsc39 ~ Var2, value = "Freq") | |
tt_table[is.na(tt_table)] <- 0 | |
tt_table <- tt_table[,c(1:ncol(tt_table) - 1)] | |
write.csv(tt_table, "zzz/table_publications.csv", row.names = FALSE) | |
# plot bar chart | |
require(ggplot2) | |
tt_plot <- | |
ggplot(my_df, aes(acronym, Freq, fill = Var2)) + geom_bar(stat = "identity") + | |
theme(axis.text.x = element_text(angle = 90, hjust = 1)) | |
ggsave("zzz/chart_publications.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment