Type: | Package |
Title: | Visualise Twitter Interactions |
Version: | 0.5.3 |
Date: | 2020-01-02 |
Description: | Allows building an edge table from data frame of tweets, also provides function to build nodes and another create a temporal graph. |
License: | MIT + file LICENSE |
Depends: | R (≥ 3.2.0) |
Imports: | dplyr, igraph, purrr, rlang, magrittr, utils, tidyr, zeallot, combinat |
RoxygenNote: | 7.0.2 |
URL: | http://graphTweets.john-coene.com |
BugReports: | https://github.com/JohnCoene/graphTweets/issues |
Suggests: | rtweet, testthat |
Encoding: | UTF-8 |
NeedsCompilation: | no |
Packaged: | 2020-01-07 12:45:28 UTC; jcoe |
Author: | John Coene [aut, cre] |
Maintainer: | John Coene <jcoenep@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2020-01-08 09:00:08 UTC |
graphTweets visualise Twitter Interactions.
Description
graphTweets visualise Twitter Interactions.
Functions
-
gt_edges
- get edges from tweets -
gt_nodes
- add meta-data to vertices -
gt_co_edges
- Co mentions networks -
gt_dyn
- create dynamic graphs -
gt_collect
- collect edges and nodes -
gt_graph
- create graph -
gt_save
- save graph to file
Examples
## Not run:
library(rtweet)
tweets <- search_tweets("#rstats")
library(graphTweets)
# simple network
tweets %>%
gt_edges(screen_name, mentions_screen_name) %>% # get edges
gt_nodes %>% # get nodes
gt_graph %>% # build igraph object
plot(.)
## End(Not run)
Collect
Description
Collect
Usage
gt_collect(gt)
Arguments
gt |
An object of class |
Value
A named list of tibble 1) edges and 2) nodes.
Examples
# 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
Dynamise
Description
Create a dynamic graph to import in Gephi.
Usage
gt_dyn(gt, lifetime = Inf)
Arguments
gt |
An object of class |
lifetime |
Lifetime of a tweet in milliseconds, defaults to |
Examples
## 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)
Edges
Description
Get edges from data.frame of tweets.
Usage
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)
Arguments
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. |
Functions
gt_edges
: Build edgesgt_preproc_edges
: Pre-process edgesgt_edges_bind
: Append edges
Edges from text
Description
Get edges from data.frame of tweets.
Usage
gt_edges_from_text(data, id, source, tweets, ...)
gt_edges_from_text_(
data,
id = "status_id",
source = "screen_name",
tweets = "text",
...
)
Arguments
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. |
Details
The tl
arguments stands for tolower
and allows converting the #hashtags to lower case as
these often duplicated, i.e.: #python #Python.
Value
An object of class graphTweets
.
Functions
gt_edges
- Build networks of users.gt_co_edges
- Build networks of users to hashtags.
Examples
# 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)
Graph
Description
Build igraph
object.
Usage
gt_graph(gt)
Arguments
gt |
An object of class |
Value
An object of class igraph
.
Examples
# 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
Nodes
Description
Get nodes from a graphTweets
object.
Usage
gt_nodes(gt, meta = FALSE)
gt_add_meta(gt, name, source, target)
Arguments
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. |
Value
An object of class graphTweets
.
Functions
gt_nodes
: Builds nodesgt_add_meta
: Add meta data to the nodes. The meta data is taken from the edges.
Save
Description
Save the graph to file.
Usage
gt_save(gt, file = "graphTweets.graphml", format = "graphml", ...)
Arguments
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. |
Examples
## 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)
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.