Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
upgrade metar and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Jul 22, 2020
1 parent 4896452 commit d2843d7
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 7,031 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
defaults:
run:
shell: Rscript {0}
# this needs to be the same as in Dockerfile
container:
# this needs to be the same as in Dockerfile
image: subugoe/muggle-onbuild:f60004c31979947dab53fbf9cfbb0e7f1c4bea55
steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,20 @@ LazyData: true
Roxygen: list(markdown = TRUE)
Suggests:
rmarkdown,
knitr,
jsonlite,
ggalt,
scales,
forcats,
cowplot,
readxl,
bookdown,
flexdashboard,
viridis,
plotly,
shiny,
DT,
writexl,
echarts4r,
metaR,
metar,
DBI,
dbplyr,
haven,
Expand All @@ -90,4 +88,4 @@ Imports:
ggplot2,
rlang
Remotes:
subugoe/metaR@5543b34c49b339c8e91217912d07662415384cbe
subugoe/metar@7ccc2a0
2 changes: 1 addition & 1 deletion R/plots.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Color palettes
#' Colors used in the hybrid open access dashboard, based on [metaR::ugoe_pal()]
#' Colors used in the hybrid open access dashboard, based on [metar::ugoe_pal()]
#' @family visualisation functions
#' @name colors
NULL
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<!-- badges: start -->
[![Main](https://github.com/subugoe/hoad/workflows/.github/workflows/main.yaml/badge.svg)](https://github.com/subugoe/hoad/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/hoad)](https://CRAN.R-project.org/package=hoad)
[![Codecov test coverage](https://codecov.io/gh/subugoe/hoad/branch/master/graph/badge.svg)](https://codecov.io/gh/subugoe/hoad)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Codecov test coverage](https://codecov.io/gh/subugoe/hoad/branch/master/graph/badge.svg)](https://codecov.io/gh/subugoe/hoad?branch=master)
<!-- badges: end -->
Expand Down
97 changes: 55 additions & 42 deletions inst/app/dashboard.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
css: ugoe_bootswatch.css
css: !expr metar::subugoe_template()$assets$css
runtime: shiny
---

Expand All @@ -28,7 +28,7 @@ library(stringr)
hybrid_df <- readr::read_csv(file = path_extdat("hybrid_publications.csv")) %>%
mutate(license = fct_infreq(license)) %>%
mutate(publisher = fct_infreq(publisher)) %>%
mutate(year = factor(issued, levels = c("2013", "2014", "2015","2016", "2017", "2018", "2019", "2020"))) %>%
mutate(year = factor(issued, levels = c("2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"))) %>%
mutate(hybrid_type = ifelse(hybrid_type == "SCOAP", "SCOAP<sup>3</sup>", hybrid_type)) %>%
mutate(hybrid_type = factor(hybrid_type, levels = c("Open APC (TA)", "Open APC (Hybrid)", "SCOAP<sup>3</sup>"))) %>%
mutate(domain = paste(domain, suffix, sep = ".")) %>%
Expand Down Expand Up @@ -86,13 +86,13 @@ jn_f <- reactive({
# prepare dataset for plotting
hybrid_sub <- reactive({
if (length(unique(jn_f()$publisher)) > 1) {
if (length(unique(jn_f()$publisher)) > 1) {
hybrid_sub <- jn_f() %>%
group_by(year, yearly_all, license) %>%
count() %>%
mutate(prop = n / yearly_all)
} else if (length(unique(jn_f()$journal_title)) > 1 &&
length(unique(jn_f()$publisher)) == 1) {
length(unique(jn_f()$publisher)) == 1) {
hybrid_sub <- jn_f() %>%
group_by(year, license, yearly_publisher_volume) %>%
count() %>%
Expand Down Expand Up @@ -146,7 +146,8 @@ renderValueBox({
renderValueBox({
journal_n <- length(unique(jn_f()$journal_title))
valueBox(format(journal_n, big.mark = " ", scientific = FALSE),
icon = "fa-filter")
icon = "fa-filter"
)
})
```

Expand All @@ -156,7 +157,8 @@ renderValueBox({
renderValueBox({
hybrid_n <- nrow(jn_f())
valueBox(format(hybrid_n, big.mark = " ", scientific = FALSE),
icon = "fa-creative-commons")
icon = "fa-creative-commons"
)
})
```

Expand Down Expand Up @@ -197,12 +199,13 @@ renderPlotly({
) +
scale_x_discrete(drop = FALSE) +
scale_y_continuous(
labels = function(x)
labels = function(x) {
format(x, big.mark = " ", scientific = FALSE)
}
) +
theme_minimal() +
geom_col(position = position_stack(reverse = TRUE))
# p
# p
plotly::ggplotly(p)
})
```
Expand Down Expand Up @@ -234,8 +237,9 @@ renderPlotly({
ylab("Articles") +
scale_x_discrete(drop = FALSE) +
scale_y_continuous(
labels = function(x)
format(x, big.mark = " ", scientific = FALSE),
labels = function(x) {
format(x, big.mark = " ", scientific = FALSE)
},
breaks = scales::pretty_breaks()
) +
scale_fill_manual(
Expand Down Expand Up @@ -264,8 +268,10 @@ renderEcharts4r({
count(suffix, domain) %>%
filter(!is.na(domain)) %>%
e_charts() %>%
e_treemap(suffix, domain, n, leafDepth = "1",
name = "Corresponding Email") %>%
e_treemap(suffix, domain, n,
leafDepth = "1",
name = "Corresponding Email"
) %>%
e_tooltip(trigger = "item")
})
```
Expand Down Expand Up @@ -302,10 +308,12 @@ hybrid_df %>%
geom_bar(aes(fill = "by Publisher", label = `Proportion in %`), color = "transparent", stat = "identity") +
facet_wrap(~publisher_group, nrow = 1) +
scale_fill_manual(values = c("#b3b3b3a0", "#153268"), name = "") +
labs(x = "Year", y = "Hybrid OA Articles") +
labs(x = "Year", y = "Hybrid OA Articles") +
theme_minimal() +
theme(legend.position = "top",
legend.justification = "right") +
theme(
legend.position = "top",
legend.justification = "right"
) +
scale_y_continuous(labels = scales::number_format(big.mark = " ")) +
theme(panel.grid.minor = element_blank()) +
theme(axis.ticks = element_blank()) +
Expand Down Expand Up @@ -339,14 +347,14 @@ fillRow(
output$pubplot <- renderPlotly({
if (input$Year == "All") {
tt <- hybrid_df %>%
tt <- hybrid_df %>%
filter(!is.na(license)) %>%
mutate(publisher = forcats::as_factor(publisher)) %>%
group_by(year, publisher, journal_title, yearly_jn_volume) %>%
summarize(oa = n()) %>%
mutate(prop = oa / yearly_jn_volume)
} else {
tt <- hybrid_df %>%
tt <- hybrid_df %>%
filter(!is.na(license)) %>%
mutate(publisher = forcats::as_factor(publisher)) %>%
filter(year %in% input$Year) %>%
Expand All @@ -366,8 +374,9 @@ output$pubplot <- renderPlotly({
scale_x_discrete(
drop = FALSE,
limits = rev(levels(tt$publisher)),
labels = function(x)
labels = function(x) {
str_wrap(x, width = 30)
}
) +
scale_y_continuous(labels = scales::percent)
if (input$rb == TRUE) {
Expand Down Expand Up @@ -404,13 +413,13 @@ fillCol(
output$yearplot <- renderPlotly({
if (input$Publisher == "All") {
tt <- hybrid_df %>%
tt <- hybrid_df %>%
filter(!is.na(license)) %>%
group_by(year, publisher, journal_title, yearly_jn_volume) %>%
summarize(oa = n()) %>%
mutate(prop = oa / yearly_jn_volume)
} else {
tt <- hybrid_df %>%
tt <- hybrid_df %>%
filter(!is.na(license)) %>%
filter(publisher == input$Publisher) %>%
group_by(year, publisher, journal_title, yearly_jn_volume) %>%
Expand Down Expand Up @@ -471,16 +480,16 @@ hybrid_data <- reactive({
renderDataTable(
expr = {
hybrid_data()
},
rownames = FALSE,
hybrid_data()
},
rownames = FALSE,
filter = "bottom",
options = list(
options = list(
pageLength = 4,
dom = "ftp",
columnDefs = list(list(
columnDefs = list(list(
className = "dt-head-left", targets = "_all"
))
))
)
)
```
Expand All @@ -493,13 +502,13 @@ Institutional View
my_data <- reactive({
if (!is.null(input$plot_clicked_data$name)) {
hybrid_df %>%
filter(suffix == input$plot_clicked_data$name | domain == input$plot_clicked_data$name) %>%
mutate(plot_title = ifelse(!input$plot_clicked_data$name %in% suffix,
domain,
filter(suffix == input$plot_clicked_data$name | domain == input$plot_clicked_data$name) %>%
mutate(plot_title = ifelse(!input$plot_clicked_data$name %in% suffix,
domain,
suffix
))
} else {
hybrid_df
hybrid_df
}
})
```
Expand All @@ -512,16 +521,18 @@ Column
```{r}
output$plot <- renderEcharts4r({
hybrid_df %>%
count(suffix, domain) %>%
filter(!is.na(domain)) %>%
e_charts() %>%
e_treemap(suffix, domain, n, leafDepth = "1",
name = "Corresponding Email") %>%
e_tooltip(trigger = "item")
count(suffix, domain) %>%
filter(!is.na(domain)) %>%
e_charts() %>%
e_treemap(suffix, domain, n,
leafDepth = "1",
name = "Corresponding Email"
) %>%
e_tooltip(trigger = "item")
})
output$oa_license <- renderPlotly({
ggplot(my_data(), aes(factor(year), fill = license)) +
ggplot(my_data(), aes(factor(year), fill = license)) +
geom_bar(position = position_stack(reverse = TRUE)) +
ggtitle(unique(my_data()$plot_title)) +
scale_fill_manual(
Expand All @@ -530,11 +541,12 @@ output$oa_license <- renderPlotly({
) +
scale_x_discrete("", drop = FALSE) +
scale_y_continuous("Articles",
labels = function(x)
labels = function(x) {
format(x, big.mark = " ", scientific = FALSE)
}
) +
theme_minimal() -> p
tt <- plotly::ggplotly(p, tooltip = c("y"))
tt <- plotly::ggplotly(p, tooltip = c("y"))
tt$x$data <- lapply(tt$x$data, function(x) {
x$text <- paste(x$name, x$y, sep = ": ")
x
Expand All @@ -549,16 +561,17 @@ output$oa_source <- renderPlotly({
xlab("Year") +
ylab("Articles") +
scale_y_continuous(
labels = function(x)
labels = function(x) {
format(x, big.mark = " ", scientific = FALSE)
}
) +
scale_fill_manual(
"Sources",
values = colors_source_disclosure,
na.value = "#b3b3b3a0"
) +
theme_minimal()
tt <- plotly::ggplotly(p, tooltip = c("y"))
tt <- plotly::ggplotly(p, tooltip = c("y"))
tt$x$data <- lapply(tt$x$data, function(x) {
x$text <- paste(x$name, x$y, sep = ": ")
x
Expand All @@ -584,7 +597,7 @@ Row
```{r}
renderDataTable(
expr = {
my_data() %>%
my_data() %>%
count(publisher) %>%
arrange(desc(n)) %>%
mutate(prop = round(n / sum(n) * 100, 2))
Expand Down
Loading

0 comments on commit d2843d7

Please sign in to comment.