knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(nethoser)
This vignette uses a dataset of 272 news and blog articles about the R programming language but you can collect your own data using the webhoser package which is an R wrapper to the webhoser.io API.
library(webhoser) data("webhoser")
The package only consists of one dataset and two functions:
connect
to build a graph by connecting variables.visualise
a convenience function which uses sigmajs to visualise the graph.The connect
function returns a list of nodes and edges.
g <- webhoser %>% net_con(entities.locations) class(g)
You can unpack the graph with the %<-%
assignment exported from the zeallot
package.
c(nodes, edges) %<-% g nodes %>% head %>% knitr::kable() edges %>% head %>% knitr::kable()
We can build graphs of co-mentions by only passing one variable to the connect
function. Below we plot co-mentions of personas in articles; each nodes is a person, they are connected by an edge when they are both mentioned in at least one article.
webhoser %>% net_con(entities.persons) %>% net_vis()
Below we connect sites to the location they mention in articles.
webhoser %>% net_con( thread.site, entities.locations ) %>% net_vis()
You can pass a callback function to net_con
.
cb <- function(x){ dplyr::filter(x, n > quantile(n, .5)) } webhoser %>% net_con( thread.site, entities.locations, callback = cb ) %>% net_vis()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.