Skip to contents

a plotting function for circular visualization of networks

Usage

plot_webgg(web, labels)

Arguments

web

a square S x S matrix of 0's and 1's where S is the total number of species in the web columns are consumers and rows are species that are consumed therefore a 1 in row 5 and column 8 means that species 8 eats species 5. Use the function t() if your matrices are oppositely arranged.

labels

vector of length S containin string values for the color of each consumer

Value

list with two values. The first, `plot`, a ggplot2 object accessed by object$plot. The second,`rawdat`, a data frame of raw x-y coordinates to connect with lines accessed as object$rawdat

Examples

######Large random matrix
rand.mat <- matrix(rbinom(1600,1,.2),ncol=40,nrow=40)
diag(rand.mat)<- 0
lab <- rep("Black",40)
test<- plot_webgg(rand.mat,lab)
#> Error in discrete_scale(aesthetic, "manual", pal, breaks = breaks, limits = limits,     ...): unused argument (legend = FALSE)
test$plot
#> Error in eval(expr, envir, enclos): object 'test' not found
####Small random matrix with colored links
rand.mat <- matrix(rbinom(100,1,.3),ncol=10,nrow=10)
diag(rand.mat)<- 0
lab <- c(rep("blue",3),rep("red",7))
test<- plot_webgg(rand.mat,lab)
#> Error in discrete_scale(aesthetic, "manual", pal, breaks = breaks, limits = limits,     ...): unused argument (legend = FALSE)
test$plot
#> Error in eval(expr, envir, enclos): object 'test' not found
#Finally an example generated with a niche-foodweb simulation from Williams and Martinez: http://www.nature.com/nature/journal/v404/n6774/abs/404180a0.html
#  I have a brief undocumented function below to generate the web, it requires S (# of species) and C (connectivity)
niche.model <- function(S,C){
  new.mat <- matrix(0,nrow=S,ncol=S)
  ci <- vector()
  niche <- runif(S,0,1)
  r <- rbeta(S,1,((1/(2*C))-1)) * niche
  for(i in 1:S){ci[i]<-runif(1,r[i]/2,niche[i])}

  #now set the smallest species niche value to have an n of 0
  r[which(niche==min(niche))] <- .00000001
  for(i in 1:S){
    for(j in 1:S){
      if(niche[j] > (ci[i]-(.5*r[i])) && niche[j]< (ci[i]+.5*r[i])){new.mat[j,i]<-1}
    }
  }
  new.mat <- new.mat[,order(apply(new.mat,2,sum))]
  return(new.mat)
}
###Plot
niche.web <- niche.model(20,.25)
labs <- rep("Black",20)
niche.plot <- plot_webgg(niche.web,labs)
#> Error in discrete_scale(aesthetic, "manual", pal, breaks = breaks, limits = limits,     ...): unused argument (legend = FALSE)
niche.plot$plot
#> Error in eval(expr, envir, enclos): object 'niche.plot' not found