Getting data in, part 1

Here's the process for reading in one file

# change to your path
data<-read.csv("~/github/sac/metro/metro.csv")
# change row names with first column of plant names
row.names(data) <- data[,1] 
# remove first column
data <- data[,-1] 
# change all NA's to zeros
data[is.na(data)] <- 0 

Getting data in, part 2

Or you can read in all files at once and manipulate structure in lapply call

setwd("~/github/sac/metro") # set directory
listoffiles <- dir("~/github/sac/metro") # get all file names

# Define a function to do all manipulation
foo <- function(y){  
  x <- read.csv(y)
  row.names(x) <- x[,1]
  x <- x[,-1]
  x[is.na(x)] <- 0
  x
}

# Apply foo fxn to all files
listofnetowrks <- lapply(listoffiles, foo)

Quick plot

library(bipartite)
plotweb(data)

plot of chunk unnamed-chunk-3

Calculate network metrics

library(bipartite)
networklevel(data, index=c('nestedness','ISA','H2'))
                    nestedness interaction strength asymmetry 
                      3.010058                       0.006573 
                            H2 
                      0.376138 

Comparing metrics - manipulate data

get data

library(bipartite)
threenetworks <- list(small1976, barrett1987, motten1982)
out <- lapply(threenetworks, function(x) networklevel(x, index=c('nestedness','ISA','H2')))
names(out) <- c('small1976', 'barrett1987', 'motten1982')
library(plyr)
df <- ldply(out)

manipulate data

library(reshape2)
df_melt <- melt(df)

Comparing metrics - plot 1

library(ggplot2)
ggplot(df_melt, aes(variable, value, color=.id)) +
  geom_jitter(size=5) +
  theme_bw(base_size=18)

plot of chunk plot1

Comparing metrics - plot 2

ggplot(df_melt, aes(.id, value)) +
  geom_jitter(size=5) +
  theme_bw(base_size=18) +
  facet_wrap(~ variable)

plot of chunk plot2