This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
install.packages('bipartite')
Error in install.packages : Updating loaded packages
install.packages('rglobi')
Error in install.packages : Updating loaded packages
install.packages('tidyverse')
Installing package into ‘/media/jorrit/branta/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/tidyverse_1.3.1.tar.gz'
Content type 'application/x-gzip' length 702779 bytes (686 KB)
==================================================
downloaded 686 KB
* installing *source* package ‘tidyverse’ ...
** package ‘tidyverse’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (tidyverse)
The downloaded source packages are in
‘/tmp/Rtmp15lpHk/downloaded_packages’
install.packages("bipartite")
Installing package into ‘/media/jorrit/branta/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/bipartite_2.16.tar.gz'
Content type 'application/x-gzip' length 1839736 bytes (1.8 MB)
==================================================
downloaded 1.8 MB
* installing *source* package ‘bipartite’ ...
** package ‘bipartite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-5XUBcI/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c bmn5.cc -o bmn5.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-5XUBcI/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c identifyModules.cc -o identifyModules.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-5XUBcI/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c init.c -o init.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o bipartite.so bmn5.o identifyModules.o init.o -L/usr/lib/R/lib -lR
installing to /media/jorrit/branta/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-bipartite/00new/bipartite/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (bipartite)
The downloaded source packages are in
‘/tmp/Rtmp15lpHk/downloaded_packages’
install.packages("rglobi")
Error in install.packages : Updating loaded packages
Plot some visualizations for pre-canned olito2015 dataset.
library(bipartite)
par(xpd=T)
plotweb(bipartite::olito2015)
visweb(bipartite::olito2015)
Warning in visweb(bipartite::olito2015) : Object converted to matrix.
A small hard coded network to get a sense of the data structures.
library(bipartite)
testdata <- data.frame(higher = c("bee1","bee1","bee1","bee2","bee1","bee3"),
lower = c("plant1","plant2","plant1","plant2","plant3","plant4"),
webID = c("meadow","meadow","meadow","meadow","meadow","meadow"), freq=c(5,9,1,2,3,7))
dim(testdata)
class(testdata)
summary(testdata)
bipartite::frame2webs(testdata)-> SmallTestWeb
SmallTestWeb
bipartite::plotweb(SmallTestWeb$meadow)
Use GloBI rglobi Web API to get specific interaction records
library(dplyr)
oakfun <- rglobi::get_interactions_by_taxa(sourcetaxon = "Fungi", targettaxon="Quercus", showfield=c('source_taxon_name', 'target_taxon_name')) %>%
select(source_taxon_name, target_taxon_name) %>%
mutate(webID = 'web1')
head(oakfun)
Alternatively, use a static file
# about 33k interactions
oakfun <- readr::read_csv('../data/oakfungi.csv') %>%
select(source_taxon_name, target_taxon_name) %>%
mutate(webID = 'web1')
head(oakfun)
Or a smaller static file
# a smaller 100 record sample
oakfun <- readr::read_csv('../data/oakfungi-sample.csv') %>%
select(source_taxon_name, target_taxon_name) %>%
mutate(webID = 'web1')
head(oakfun)
Now visualize the retrieved globi data
par(xpd=T)
oakfun_web <- bipartite::frame2webs(oakfun, varnames = c("source_taxon_name", "target_taxon_name", "webID"))
bipartite::plotweb(oakfun_web$web1)
bipartite::visweb(oakfun_web$web1)
Here’s some examples of working with network metrics. See bipartite vignette for more examples.
group_metrics <- bipartite::grouplevel(oakfun_web$web1, level="both", index=c("mean number of links", "weighted cluster coefficient", "effective partners", "niche overlap"), dist="bray")
head(group_metrics)
species_metrics <- bipartite::specieslevel(oakfun_web$web1, level="lower", index=c("normalised degree", "PDI", "effective partners"), PDI.normalise=F)
head(species_metrics)