R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# Libraries
library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
library(networkD3)

wew_links <- data.frame(
  food=c(1,4,3,0,1,3,5,4),
  eater=c(0,0,1,2,2,2,3,5),
  times_eaten=c(1,1)
)

wew_nodes <- data.frame(
  species=c("Virginia Opossum", "Eastern Rat Snake", "Red-Shouldered Hawk", "Northern Short-Tailed Shrew", "Jewelweed", "Pavement Ant"),
  group=c("Primary Consumer", "Primary Consumer", "Apex Predator", "Primary Consumer", "Producer", "Primary Consumer"), 
  size=c(1,1,1,1,1,1))

wew <- forceNetwork(Links = wew_links, Nodes = wew_nodes,
             Source = "food", Target = "eater",
             Value = "times_eaten", NodeID = "species",
             Group = "group", opacity = 0.8,
             arrows = TRUE, legend = TRUE,
             fontFamily = "mono",
             colourScale = JS("d3.scaleOrdinal(d3.schemeCategory10);"))
wew
# save the widget
library(htmlwidgets)
## 
## Attaching package: 'htmlwidgets'
## The following object is masked from 'package:networkD3':
## 
##     JS
saveWidget(wew, file="wewfile.html", selfcontained = TRUE)