Created
June 30, 2019 10:34
-
-
Save mtmorgan/464028015c4944b45832f9c0d1d26b6a to your computer and use it in GitHub Desktop.
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
## package biocViews dumbbell | |
library(BiocPkgTools) | |
library(dplyr) | |
library(tidyr) | |
library(graph) | |
library(biocViews) | |
data(biocViewsVocab) | |
first <- biocPkgList("3.7") %>% select(Package) | |
second <- biocPkgList("3.9") %>% select(Package, biocViews) %>% unnest() | |
second <- second %>% | |
mutate(New = ifelse(Package %in% first$Package, "Existing", "New")) | |
views <- second %>% group_by(biocViews, New) %>% count() %>% | |
spread(New, n) %>% arrange(desc(New)) | |
new_pkgs <- anti_join(second, first, by="Package") | |
edges <- tibble(edges = edgeNames(biocViewsVocab)) %>% | |
separate(edges, c("from", "to"), sep="~") | |
flds <- c("ResearchField", "As.Character", "Technology", "Sequencing") | |
ppn <- left_join(edges, views, by = c(to="biocViews")) %>% | |
filter(from %in% flds, !(is.na(Existing) & is.na(New))) %>% | |
replace_na(list(Existing = 0, New = 0)) %>% | |
arrange(from, desc(New)) %>% | |
group_by(from) %>% | |
mutate(Existing = Existing / sum(Existing), New = New / sum(New)) %>% | |
ungroup() | |
rsrch_fld <- ppn %>% filter(from == "ResearchField") %>% | |
mutate(to = factor(to, levels = to)) | |
assay_domain <- ppn %>% filter(from == "AssayDomain") %>% | |
mutate(to = factor(to, levels = to)) | |
tech <- ppn %>% filter(from == "Technology") %>% | |
mutate(to = factor(to, levels = to)) | |
sequencing <- ppn %>% filter(from == "Sequencing") %>% | |
mutate(to = factor(to, levels = to)) | |
library(ggplot2) | |
library(ggalt) | |
dumbbell <- | |
function(df, ylab, pdf = TRUE) | |
{ | |
p <- ggplot(df, aes(x = Existing, xend = New, y = to)) + | |
geom_dumbbell(colour="#a3c4dc", size=4, colour_xend="#0e668b") + | |
labs(title = ylab, x = "Proportion of packages", y = NULL) + | |
xlim(0, 0.6) | |
if (pdf) { | |
pdf( | |
paste0(gsub(" +", "-", tolower(ylab)), "-dumbbell.pdf"), | |
height = 5 | |
) | |
print(p) | |
dev.off() | |
} else p | |
} | |
dumbbell(rsrch_fld, "Research field") | |
dumbbell(assay_domain, "Assay domain") | |
dumbbell(sequencing, "Sequencing method") | |
dumbbell(tech, "Technology") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment