Title: | Visualise Twitter Interactions |
---|---|
Description: | Allows building an edge table from data frame of tweets, also provides function to build nodes and another create a temporal graph. |
Authors: | John Coene [aut, cre] |
Maintainer: | John Coene <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.3 |
Built: | 2024-11-18 04:54:19 UTC |
Source: | https://github.com/johncoene/graphtweets |
Collect
gt_collect(gt)
gt_collect(gt)
gt |
An object of class |
A named list of tibble 1) edges and 2) nodes.
# simulate dataset tweets <- data.frame( text = c("I tweet @you about @him", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, status_id) %>% gt_nodes() %>% gt_collect() -> net
# simulate dataset tweets <- data.frame( text = c("I tweet @you about @him", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, status_id) %>% gt_nodes() %>% gt_collect() -> net
Create a dynamic graph to import in Gephi.
gt_dyn(gt, lifetime = Inf)
gt_dyn(gt, lifetime = Inf)
gt |
An object of class |
lifetime |
Lifetime of a tweet in milliseconds, defaults to |
## Not run: # simulate dataset tweets <- data.frame( text = c("I tweet @you about @him and @her", "I tweet @me about @you"), screen_name = c("me", "him"), created_at = c(Sys.time(), Sys.time() + 10000), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, status_id, "created_at") %>% gt_nodes() %>% gt_dyn() %>% gt_collect() -> net ## End(Not run)
## Not run: # simulate dataset tweets <- data.frame( text = c("I tweet @you about @him and @her", "I tweet @me about @you"), screen_name = c("me", "him"), created_at = c(Sys.time(), Sys.time() + 10000), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, status_id, "created_at") %>% gt_nodes() %>% gt_dyn() %>% gt_collect() -> net ## End(Not run)
Get edges from data.frame of tweets.
gt_edges(data, source, target, ..., tl = TRUE) gt_preproc_edges(gt, func) gt_edges_bind(gt, source, target, ..., tl = TRUE) gt_co_edges(data, col, tl = TRUE) gt_co_edges_bind(gt, col, tl = TRUE)
gt_edges(data, source, target, ..., tl = TRUE) gt_preproc_edges(gt, func) gt_edges_bind(gt, source, target, ..., tl = TRUE) gt_co_edges(data, col, tl = TRUE) gt_co_edges_bind(gt, col, tl = TRUE)
data |
Data.frame of tweets, usually returned by the |
source |
Author of tweets. |
target |
Edges target. |
... |
any other column name, see examples. |
tl |
Set to |
gt |
An object of class |
func |
Function to pre-process edges, takes edges as constructed by |
col |
Column containing co-mentions. |
gt_edges
: Build edges
gt_preproc_edges
: Pre-process edges
gt_edges_bind
: Append edges
Get edges from data.frame of tweets.
gt_edges_from_text(data, id, source, tweets, ...) gt_edges_from_text_( data, id = "status_id", source = "screen_name", tweets = "text", ... )
gt_edges_from_text(data, id, source, tweets, ...) gt_edges_from_text_( data, id = "status_id", source = "screen_name", tweets = "text", ... )
data |
Data.frame of tweets, usually returned by the |
id |
tweets unique id. |
source |
Author of tweets. |
tweets |
Column containing tweets. |
... |
any other column name. |
The tl
arguments stands for tolower
and allows converting the #hashtags to lower case as
these often duplicated, i.e.: #python #Python.
An object of class graphTweets
.
gt_edges
- Build networks of users.
gt_co_edges
- Build networks of users to hashtags.
# simulate dataset tweets <- data.frame( text = c("I tweet @you about @him and @her", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), status_id = c(1, 2), hashtags = c("rstats", "Python"), stringsAsFactors = FALSE ) tweets %>% gt_edges_from_text(status_id, screen_name, text)
# simulate dataset tweets <- data.frame( text = c("I tweet @you about @him and @her", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), status_id = c(1, 2), hashtags = c("rstats", "Python"), stringsAsFactors = FALSE ) tweets %>% gt_edges_from_text(status_id, screen_name, text)
Build igraph
object.
gt_graph(gt)
gt_graph(gt)
gt |
An object of class |
An object of class igraph
.
# simulate dataset tweets <- data.frame( text = c("I tweet @you about @him", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, status_id) %>% gt_nodes() %>% gt_graph() -> net
# simulate dataset tweets <- data.frame( text = c("I tweet @you about @him", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, status_id) %>% gt_nodes() %>% gt_graph() -> net
Get nodes from a graphTweets
object.
gt_nodes(gt, meta = FALSE) gt_add_meta(gt, name, source, target)
gt_nodes(gt, meta = FALSE) gt_add_meta(gt, name, source, target)
gt |
An object of class |
meta |
Set to |
name |
Name of column to create. |
source , target
|
Name of column too apply to edge source and target. |
An object of class graphTweets
.
gt_nodes
: Builds nodes
gt_add_meta
: Add meta data to the nodes. The meta data is taken from the edges.
Save the graph to file.
gt_save(gt, file = "graphTweets.graphml", format = "graphml", ...)
gt_save(gt, file = "graphTweets.graphml", format = "graphml", ...)
gt |
An object of class |
file |
File name including extension ( |
format |
Format file format, see write_graph. |
... |
Any other argument to pass to write_graph. |
## Not run: # simulate dataset tweets <- data.frame( text = c("I tweet @you about @him", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), created_at = c(Sys.time(), Sys.time() + 15000), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, "created_at") %>% gt_nodes(TRUE) %>% gt_dyn() %>% gt_save() ## End(Not run)
## Not run: # simulate dataset tweets <- data.frame( text = c("I tweet @you about @him", "I tweet @me about @you"), screen_name = c("me", "him"), retweet_count = c(19, 5), created_at = c(Sys.time(), Sys.time() + 15000), status_id = c(1, 2), stringsAsFactors = FALSE ) tweets %>% gt_edges(text, screen_name, "created_at") %>% gt_nodes(TRUE) %>% gt_dyn() %>% gt_save() ## End(Not run)