README.md

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)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(purrr)
library(ggraph)
#> Loading required package: ggplot2
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter
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.