knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

Travis build status

phrasenets

Phrasenets lets you build (very) simple but interpretable and insightful phrase networks, see the website for more details on their nature.

Installation

You can install the packages from Github with:

# install.packages("remotes")
remotes::install_github("news-r/phrasenets")

Example

library(dplyr)
library(purrr)
library(ggraph)
library(tidygraph)
library(phrasenets)

data(reuters)

# create a graph for each commodity
subgraphs <- reuters %>% 
  group_split(category) %>% 
  map(phrase_net, text = text) %>% 
  map(filter_net, c("a", "the")) %>% 
  map(filter, occurences > 1) %>% 
  map(as_tbl_graph) %>% 
  map(function(x){
    mutate(x, size = centrality_degree())
  })

plot_it <- function(g, commodity){
  ggraph(g, layout = 'kk') + 
    geom_edge_fan(show.legend = FALSE) + 
    geom_node_point(aes(size = size, colour = size), show.legend = FALSE) + 
    labs(caption = tools::toTitleCase(commodity))
} 

commodities <- unique(reuters$category)

map2(subgraphs, commodities, plot_it) %>% 
  patchwork::wrap_plots(ncol = 2)


news-r/phrasenets documentation built on Nov. 4, 2019, 9:40 p.m.