-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query Open Alex for UoA, get OA proportions, plot
- Loading branch information
1 parent
1329b4c
commit 73826b1
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
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
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 |
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
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("%") | ||
``` | ||
|