knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(nethoser)

Data

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")

Basics

The package only consists of one dataset and two functions:

  1. connect to build a graph by connecting variables.
  2. 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()

Co-mentions

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()

Graph

Below we connect sites to the location they mention in articles.

webhoser  %>% 
    net_con(
        thread.site,
        entities.locations
    ) %>% 
    net_vis()

Callback

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()


JohnCoene/nethoser documentation built on June 13, 2019, 8:33 a.m.