Skip to content

Commit

Permalink
Major update
Browse files Browse the repository at this point in the history
New version of the script, now with shorter, faster, and easier to reproduce code.
  • Loading branch information
marmello77 committed Oct 23, 2020
1 parent cd96cc9 commit 04b47ec
Show file tree
Hide file tree
Showing 13 changed files with 522 additions and 412 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

.DS_Store
.Rhistory
75 changes: 69 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,80 @@
# How to draw and analyze multilayer networks in R
# multilayer-networks

A tutorial on how to draw and analyze multilayer networks in R.

[Ecological Synthesis Lab](https://marcomellolab.wordpress.com) (SintECO).

Authors: Marco Mello & Renata Muylaert.

E-mail: marmello@usp.br.

How to cite: Mello MAR & Muylaert RL. 2017. Drawing and analyzing multilayer networks in R. Ecological Synthesis Lab of the University of São Paulo, Brazil.

Published on November 23rd, 2017 (English version).
First published on November 23rd, 2017 (English version).

<a href="https://doi.org/10.5281/zenodo.1487539"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.1487539.svg" alt="DOI"></a>

Run in R 3.4.2 (2017-09-28) -- "Short Summer"
Run in R version 4.0.2 (2020-06-22) -- "Taking Off Again"

Disclaimer: You may use this software freely for any purposes at your own risk. We assume no responsibility or liability for the use of this software, convey no license or title under any patent, copyright, or mask work right to the product. We reserve the right to make changes in the software without notification. We also make no representation or warranty that such application will be suitable for the specified use without further testing or modification. If this software helps you produce any academic work (paper, book, chapter, dissertation, report, talk, lecture or similar), please acknowledge the authors and cite the source, using the DOI or URL of this GitHub repository.


## Functionality and origin

The first version of this script was written as part of the analysis carried out by [Mello et al. (2019, NatureEcoEvo)](https://doi.org/10.1038/s41559-019-1002-3). Since then, we have been working on making the code shorter, faster, and easier to be used by other people interested in the same topics. You may use this code to learn how to input data on multilayer networks in R, as well to visualize those data as multilayer graphs.


## List of folders and files

1. data (folder)

a. net1.xlsx -> complete data set from Genrich et al. (2017). Interactions between marsupials, rodents, and plants.

b. net1an.txt -> angatonistic layer of net1. Seed destruction by marsupials and rodents.

c. net1links.txt -> the links (edges) of net1 with additional attributes.

d. net1mu.txt -> mutualistic layer of net1. Seed dispersal by marsupials and rodents.

e. net1nodes.txt -> the nodes (vertices) of net1 with additional attributes.


2. figures (folder)

a.net1.png -> multilayer graph of net1.


3. multilayer-networks -> script to draw and analyze multilayer networks.


## Instructions

Follow the instructions provided in the script "multilayer-networks.R".


## Data source

* Genrich, C. M., Mello, M. A. R., Silveira, F. A. O., Bronstein, J. L., & Paglia, A. P. (2017). [Duality of interaction outcomes in a plant-frugivore multilayer network](https://doi.org/10.1111/oik.03825). Oikos, 126(3), 361–368. doi: 10.1111/oik.03825


## Feedback

If you have any questions, corrections, or suggestions, please feel free to open and [issue](https://github.com/marmello77/multilayer-networks/issues) or make a [pull request](https://github.com/marmello77/multilayer-networks/pulls).


## Acknowledgments

We thank our labmates and our sponsors, especially the Alexander von Humboldt-Stiftung, CNPq, CAPES, and FAPESP, who gave us grants, fellowships, and scholarships. Pedro Jordano and Carsten Dormann helped us take our first steps in analyzing and drawing networks in R. Special thanks go to Katherine Ognyanova, who gave us invaluable tips on advanced network drawing in R. We strongly recommend her [online tutorial](http://kateto.net/network-visualization). Last, but not least, we thank the [Stack Overflow Community](https://stackoverflow.com), where we solve most of our coding dilemmas. A dilemma related to converting incidence matrices to make a multilayer network was solved [here](https://stackoverflow.com/questions/64486982/how-to-unite-two-graphs-in-r-to-form-a-multilayer-network).


## Suggested readings

* Barabasi, A.L. (2016) [Network Science](http://barabasi.com/networksciencebook/), 1st ed. Cambridge University Press, Cambridge.

* Bianconi, G. (2018). [Multilayer Networks: Structure and Function](https://amzn.to/31SAdRl). (1st ed.). Oxford: Oxford University Press.

* Mello MAR, Muylaert RL, Pinheiro RBP & Félix GMF. 2016. [Guia para análise de redes ecológicas](https://marcomellolab.wordpress.com/software/). Edição dos autores, Belo Horizonte. 112 p. ISBN-13: 978-85-921757-0-2.

* Mello, M. A. R., Felix, G. M., Pinheiro, R. B. P., Muylaert, R. L., Geiselman, C., Santana, S. E., … Stevens, R. D. (2019). [Insights into the assembly rules of a continent-wide multilayer network](https://doi.org/10.1038/s41559-019-1002-3). Nature Ecology & Evolution, 3(11), 1525–1532.

* Ognyanova K. 2019. [Static and dynamic network visualization with R](http://kateto.net/network-visualization).

Disclaimer: You may use this software freely for commercial or non-comercial purposes at your own risk. We assume no responsibility or liability for the use of this software, convey no license or title under any patent, copyright, or mask work right to the product. We reserve the right to make changes in the software without notification. We also make no representation or warranty that such application will be suitable for the specified use without further testing or modification. If this software helps you produce any academic work (paper, book, chapter, dissertation etc.), please acknowledge the authors and cite the source, using the DOI provided and the URL to this GitHub repository.
* Pilosof, S., Porter, M. A., Pascual, M., & Kéfi, S. (2017). [The multilayer nature of ecological networks](https://doi.org/10.1038/s41559-017-0101). Nature Ecology & Evolution, 1(4), 0101.
1 change: 0 additions & 1 deletion antagonistic.txt

This file was deleted.

Binary file added data/net1.xlsx
Binary file not shown.
10 changes: 10 additions & 0 deletions data/net1an.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ByrSp CamAda CecHol CecPac CecGla ChiAlb CocAur ErytSp EuphSp FicuSp LeaAur LeaCor LeanSp MicAlb MicLig MicPep MicSp1 MorSp1 MorSp2 MorSp3 MorSp5 MorSp6 MorSp7 MorSp8 MorSp9 MyrSp1 MyrSp2 PsidSp RubSp1 RubSp2 SabBra SolaSp TocFor VisBra
CerSco 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CerSub 0 0 0 13 12 0 19 0 0 0 3 0 1 0 0 2 0 0 0 0 0 0 0 72 9 0 0 0 0 0 11 0 0 0
DidAlb 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 5 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0
DidAur 0 0 0 6 11 0 0 1 3 2 0 0 0 1 50 0 0 0 1 2 0 1 19 0 0 2 2 0 0 0 0 0 0 3
MonDom 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
NecLas 0 20 0 0 0 3 0 0 0 0 15 4 2 0 0 0 0 0 0 0 0 0 0 10 58 0 9 18 0 0 0 2 0 0
OliSp 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PhiFre 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
GueIng 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
146 changes: 73 additions & 73 deletions links1.txt → data/net1links.txt
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
animals plants weight layer
GueIng ByrSp 2 antagonistic
NecLas CamAda 20 antagonistic
PhiFre CecHol 1 antagonistic
CerSub CecPac 13 antagonistic
DidAur CecPac 6 antagonistic
PhiFre CecPac 1 antagonistic
CerSub CecGla 12 antagonistic
DidAur CecGla 11 antagonistic
NecLas ChiAlb 3 antagonistic
CerSco CocAur 6 antagonistic
CerSub CocAur 19 antagonistic
DidAur ErytSp 1 antagonistic
DidAur EuphSp 3 antagonistic
DidAur FicuSp 2 antagonistic
CerSub LeaAur 3 antagonistic
NecLas LeaAur 15 antagonistic
NecLas LeaCor 4 antagonistic
CerSub LeanSp 1 antagonistic
NecLas LeanSp 2 antagonistic
DidAur MicAlb 1 antagonistic
DidAur MicLig 50 antagonistic
CerSub MicPep 2 antagonistic
DidAlb MicSp1 3 antagonistic
DidAlb MorSp1 5 antagonistic
DidAur MorSp2 1 antagonistic
DidAur MorSp3 2 antagonistic
PhiFre MorSp5 1 antagonistic
DidAur MorSp6 1 antagonistic
DidAur MorSp7 19 antagonistic
CerSub MorSp8 72 antagonistic
NecLas MorSp8 10 antagonistic
CerSub MorSp9 9 antagonistic
NecLas MorSp9 58 antagonistic
DidAur MyrSp1 2 antagonistic
DidAur MyrSp2 2 antagonistic
NecLas MyrSp2 9 antagonistic
MonDom PsidSp 1 antagonistic
NecLas PsidSp 18 antagonistic
DidAlb RubSp1 1 antagonistic
CerSub SabBra 11 antagonistic
NecLas SolaSp 2 antagonistic
DidAlb TocFor 1 antagonistic
DidAur VisBra 3 antagonistic
NecLas CamAda 1 mutualistic
CerSub CecPac 9 mutualistic
DidAur CecPac 12 mutualistic
CerSub CecGla 3 mutualistic
DidAur CecGla 4 mutualistic
NecLas ChiAlb 1 mutualistic
CerSco CocAur 1 mutualistic
CerSub CocAur 2 mutualistic
DidAur CocAur 1 mutualistic
DidAur ErytSp 6 mutualistic
DidAur EuphSp 8 mutualistic
NecLas LeaAur 12 mutualistic
NecLas LeaCor 2 mutualistic
DidAur MicLig 5 mutualistic
CerSub MicPep 1 mutualistic
DidAlb MicSp1 1 mutualistic
DidAlb MorSp1 2 mutualistic
DidAur MorSp7 36 mutualistic
OliSp MorSp7 1 mutualistic
MonDom MorSp9 2 mutualistic
NecLas MorSp9 62 mutualistic
DidAur MyrSp2 7 mutualistic
NecLas MyrSp2 1 mutualistic
CerSub PsidSp 2 mutualistic
MonDom PsidSp 1 mutualistic
NecLas PsidSp 24 mutualistic
DidAlb RubSp1 3 mutualistic
PhiFre RubSp2 1 mutualistic
NecLas SolaSp 5 mutualistic
animals plants weight layer
GueIng ByrSp 2 antagonistic
NecLas CamAda 20 antagonistic
PhiFre CecHol 1 antagonistic
CerSub CecPac 13 antagonistic
DidAur CecPac 6 antagonistic
PhiFre CecPac 1 antagonistic
CerSub CecGla 12 antagonistic
DidAur CecGla 11 antagonistic
NecLas ChiAlb 3 antagonistic
CerSco CocAur 6 antagonistic
CerSub CocAur 19 antagonistic
DidAur ErytSp 1 antagonistic
DidAur EuphSp 3 antagonistic
DidAur FicuSp 2 antagonistic
CerSub LeaAur 3 antagonistic
NecLas LeaAur 15 antagonistic
NecLas LeaCor 4 antagonistic
CerSub LeanSp 1 antagonistic
NecLas LeanSp 2 antagonistic
DidAur MicAlb 1 antagonistic
DidAur MicLig 50 antagonistic
CerSub MicPep 2 antagonistic
DidAlb MicSp1 3 antagonistic
DidAlb MorSp1 5 antagonistic
DidAur MorSp2 1 antagonistic
DidAur MorSp3 2 antagonistic
PhiFre MorSp5 1 antagonistic
DidAur MorSp6 1 antagonistic
DidAur MorSp7 19 antagonistic
CerSub MorSp8 72 antagonistic
NecLas MorSp8 10 antagonistic
CerSub MorSp9 9 antagonistic
NecLas MorSp9 58 antagonistic
DidAur MyrSp1 2 antagonistic
DidAur MyrSp2 2 antagonistic
NecLas MyrSp2 9 antagonistic
MonDom PsidSp 1 antagonistic
NecLas PsidSp 18 antagonistic
DidAlb RubSp1 1 antagonistic
CerSub SabBra 11 antagonistic
NecLas SolaSp 2 antagonistic
DidAlb TocFor 1 antagonistic
DidAur VisBra 3 antagonistic
NecLas CamAda 1 mutualistic
CerSub CecPac 9 mutualistic
DidAur CecPac 12 mutualistic
CerSub CecGla 3 mutualistic
DidAur CecGla 4 mutualistic
NecLas ChiAlb 1 mutualistic
CerSco CocAur 1 mutualistic
CerSub CocAur 2 mutualistic
DidAur CocAur 1 mutualistic
DidAur ErytSp 6 mutualistic
DidAur EuphSp 8 mutualistic
NecLas LeaAur 12 mutualistic
NecLas LeaCor 2 mutualistic
DidAur MicLig 5 mutualistic
CerSub MicPep 1 mutualistic
DidAlb MicSp1 1 mutualistic
DidAlb MorSp1 2 mutualistic
DidAur MorSp7 36 mutualistic
OliSp MorSp7 1 mutualistic
MonDom MorSp9 2 mutualistic
NecLas MorSp9 62 mutualistic
DidAur MyrSp2 7 mutualistic
NecLas MyrSp2 1 mutualistic
CerSub PsidSp 2 mutualistic
MonDom PsidSp 1 mutualistic
NecLas PsidSp 24 mutualistic
DidAlb RubSp1 3 mutualistic
PhiFre RubSp2 1 mutualistic
NecLas SolaSp 5 mutualistic
10 changes: 10 additions & 0 deletions data/net1mu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ByrSp CamAda CecHol CecPac CecGla ChiAlb CocAur ErytSp EuphSp FicuSp LeaAur LeaCor LeanSp MicAlb MicLig MicPep MicSp1 MorSp1 MorSp2 MorSp3 MorSp5 MorSp6 MorSp7 MorSp8 MorSp9 MyrSp1 MyrSp2 PsidSp RubSp1 RubSp2 SabBra SolaSp TocFor VisBra
CerSco 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CerSub 0 0 0 9 3 0 2 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0
DidAlb 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0
DidAur 0 0 0 12 4 0 1 6 8 0 0 0 0 0 5 0 0 0 0 0 0 0 36 0 0 0 7 0 0 0 0 0 0 0
MonDom 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 1 0 0 0 0 0 0
NecLas 0 1 0 0 0 1 0 0 0 0 12 2 0 0 0 0 0 0 0 0 0 0 0 0 62 0 1 24 0 0 0 5 0 0
OliSp 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
PhiFre 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
GueIng 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44 changes: 44 additions & 0 deletions data/net1nodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
nodes taxon captures
GueIng Animal 1
NecLas Animal 34
PhiFre Animal 2
CerSub Animal 20
DidAur Animal 6
CerSco Animal 1
DidAlb Animal 2
MonDom Animal 9
ByrSp Plant NA
CamAda Plant NA
CecHol Plant NA
CecPac Plant NA
CecGla Plant NA
ChiAlb Plant NA
CocAur Plant NA
ErytSp Plant NA
EuphSp Plant NA
FicuSp Plant NA
LeaAur Plant NA
LeaCor Plant NA
LeanSp Plant NA
MicAlb Plant NA
MicLig Plant NA
MicPep Plant NA
MicSp1 Plant NA
MorSp1 Plant NA
MorSp2 Plant NA
MorSp3 Plant NA
MorSp5 Plant NA
MorSp6 Plant NA
MorSp7 Plant NA
MorSp8 Plant NA
MorSp9 Plant NA
MyrSp1 Plant NA
MyrSp2 Plant NA
PsidSp Plant NA
RubSp1 Plant NA
SabBra Plant NA
SolaSp Plant NA
TocFor Plant NA
VisBra Plant NA
OliSp Animal NA
RubSp2 Plant NA
Binary file added figures/net1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed genrich et al 2017.xlsx
Binary file not shown.
Loading

0 comments on commit 04b47ec

Please sign in to comment.