rtweet (version 0.7.0)

network_data: Network data

Description

Convert Twitter data into a network-friendly data frame

Convert Twitter data into network graph object (igraph)

Usage

network_data(.x, .e = c("mention,retweet,reply,quote"))

network_graph(.x, .e = c("mention,retweet,reply,quote"))

Value

A from/to data edge data frame

An igraph object

Arguments

.x

Data frame returned by rtweet function

.e

Type of edge/link–i.e., "mention", "retweet", "quote", "reply". This must be a character vector of length one or more. This value will be split on punctuation and space (so you can include multiple types in the same string separated by a comma or space). The values "all" and "semantic" are assumed to mean all edge types, which is equivalent to the default value of c("mention,retweet,reply,quote")

Details

network_data returns a data frame that can easily be converted to various network classes. For direct conversion to a network object, see network_graph.

network_graph requires previous installation of the igraph package. To return a network-friendly data frame, see network_data

See Also

network_graph

network_data

Examples

Run this code

if (FALSE) {
  ## search for #rstats tweets
  rstats <- search_tweets("#rstats", n = 200)

  ## create from-to data frame representing retweet/mention/reply connections
  rstats_net <- network_data(rstats, "retweet,mention,reply")

  ## view edge data frame
  rstats_net

  ## view user_id->screen_name index
  attr(rstats_net, "idsn")

  ## if igraph is installed...
  if (requireNamespace("igraph", quietly = TRUE)) {

    ## (1) convert directly to graph object representing semantic network
    rstats_net <- network_graph(rstats)

    ## (2) plot graph via igraph.plotting
    plot(rstats_net)
  }
}

Run the code above in your browser using DataLab