Skip to content

Commit

Permalink
Query Open Alex for UoA, get OA proportions, plot
Browse files Browse the repository at this point in the history
  • Loading branch information
tesaunders committed Dec 21, 2023
1 parent 1329b4c commit 73826b1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
13 changes: 13 additions & 0 deletions oa-nz.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
58 changes: 58 additions & 0 deletions open-alex-query.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "open-alex-query"
author: "Tom Saunders"
date: "2023-12-20"
output: html_document
---

```{r}
library(jsonlite)
library(dplyr)
library(ggplot2)
options(stringsAsFactors = FALSE)
```

```{r}
# Set base url to OpenAlex API with 'works' endpoint
base_url <- "https://api.openalex.org/works"
# Choose relevant institution based on ROR
ror <- "institutions.ror:https://ror.org/03b94tp07"
# Choose filters
my_filters <- paste(c(
ror,
"is_paratext:false",
"type:article|book|book-chapter",
"from_publication_date:2020-01-01",
"to_publication_date:2022-12-31",
"is_retracted:false"),
collapse = ",")
# Select grouping
group <- "&group_by=oa_status"
# Create url
url <- paste0(base_url, "?", "filter=", my_filters, group)
# Make request and parse output
json <- (fromJSON(url))
# Convert to data frame
oa_status <- as.data.frame(json$group_by)
# Calculate percentages for each oa type
oa_status <- oa_status |>
mutate(
pc = (count/sum(count)*100),
)
# Plot
ggplot(oa_status, aes(reorder(key, -pc), pc)) +
geom_col() +
theme_classic() +
xlab("") +
ylab("%")
```

0 comments on commit 73826b1

Please sign in to comment.