Build list of edges from tweets

Share:

Description

Builds a table of edges (source, target) from a data.frame of tweets by subsetting @tags from the text.

Usage

1
getEdges(data, tweets, source, str.length = NULL, ...)

Arguments

data

data.frame of tweets, typically returned by searchTwitter, required.

tweets

Column name of tweets within data, must be a character string, required.

source

User names or ID column of tweets author, must be a character string, required.

str.length

Defaults to NULL. Shorten length of @tags (see details), to a maximum number of characters.

...

Any other columns to be passed on to the edges.

Details

The edges function takes in a data frame of tweets, typically obtained from the twitter Search or Streaming API, scrapes the content of tweets to subset the @tags subsequently forming a table of edges. @tags are subsets of regular expressions between at-signs (@) and first space (" "). Note that the table of edges returned is meant for a directed graph. Node labels can be shortened using the str.length parameters. This is useful for non-latin alphabet where nodes may be wrongly identified (i.e.: Chinese Sina Weibo data).

Author(s)

John Coene john.coene@gmail.com

See Also

twitteR and streamR packages wherefrom the data (data) can be obtained.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# simulate dataset
tweets <- data.frame(text = c("I tweet @you about @him", 
                              "I tweet @me about @you"),
                     screenName = c("me", "him"),
                     stringsAsFactors = FALSE)

# get edges
edges <- getEdges(data = tweets, tweets = "text", source = "screenName")

# use igraph to make graph object
g <- igraph::graph.data.frame(edges)
plot(g)