Skip to content

Instantly share code, notes, and snippets.

@njahn82
Last active March 5, 2019 21:18
Show Gist options
  • Select an option

  • Save njahn82/e5a4beed4f21262faf762b854459db76 to your computer and use it in GitHub Desktop.

Select an option

Save njahn82/e5a4beed4f21262faf762b854459db76 to your computer and use it in GitHub Desktop.
Unpaywall evidence type
#' bq unpaywall dump
#'
#' connect to google bg with imported jsonl Unpaywall dump
library(DBI)
library(tidyverse)
library(bigrquery)
con <- dbConnect(
bigrquery::bigquery(),
project = "api-project-764811344545",
dataset = "oadoi_full"
)
#' connection
oadoi <- tbl(con, "mongo_13_sep_18")
#' query (SQL)
my_query <- c("SELECT evidence, is_best, year, COUNT(*) AS number_of_articles
FROM `oadoi_full.mongo_13_sep_18`, UNNEST(oa_locations)
GROUP BY evidence, year, is_best")
#' call bq
dbGetQuery(con, my_query) -> my_evidence
#' plot
my_evidence %>%
filter(year %in% 2013:2018) %>%
ggplot(aes(factor(year), number_of_articles, fill = is_best)) +
geom_bar(stat = "identity") +
facet_wrap(~evidence, ncol = 3) +
scale_y_continuous(
labels = function(x)
format(x, big.mark = " ", scientific = FALSE),
breaks = scales::pretty_breaks()
) +
scale_fill_manual(
values = c("#23445D","#AE4132")
) +
theme_minimal() +
labs(x = "Year", y = "Articles", title = "Unpaywall OA evidence categories per year")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment