Package: twarc-network
twarc-networktwarc-networkbuilds a reply, quote, retweet and mention network from a file of tweets
that you've collected using twarc. It will write out the network as agexf,gml,dot, json, csv or html file. It usesnetworkxfor the graph model,pydotfor dot output, andd3for the html presentation.If you know CSS you can hack at the generated HTML file to modify the style to
suit your needs. If you come up with a more pleasing representation please send
a pull request! Exporting as a gexf, gml or dot file will allow you to import
the data into tools likeGephi,CytoscapeandGraphVizfor further
analysis and visualization.InstallTo install you will need to:pip3 install twarc-networkCollect DataFirst you will need to collect some data withtwarc:twarc2 search blacklivesmatter > tweets.jsonlOutput FormatsOnce you've got some data you can create the default D3 HTML visualization:twarc2 network tweets.jsonl network.htmlordot:twarc2 tweets.jsonl --format dot network.dotorgexf:twarc2 network tweets.jsonl --format gexf network.gexforgml:twarc2 network tweets.jsonl --format gml network.gmlor json:twarc2 network tweets.jsonl --format json network.jsonor CSV edge list:twarc2 network tweets.jsonl --format csv network.csvChanging the NodesTweets can be connected together as replies, quotes and retweets. If you would
like to see the network oriented around nodes that are tweets instead of users
you can:twarc2 network tweets.jsonl --nodes tweets network.htmlHashtags can can be connected when they are used together in a tweet. So you
can visualize a network where nodes are hashtags:twarc2 network tweets.jsonl --nodes hashtags > network.htmlChanging the EdgesBy default, when user and tweet graphs are built,
all types of interactions are used as edges:
Retweet, reply or quote in the case of tweets;
retweet, reply, quote or mention in the case of users.
But you can also limit the types considered.
For example, if you only want retweet edges, you can:twarc2 network tweets.jsonl tweets.html --edges retweetOr if you only want replies and quotes, you can:twarc2 network tweets.jsonl tweets.html --edges reply --edges quoteComponent SizesDepending on the data you are analyzing it can be helpful to remove weakly connected components in
the graph that are smaller than some number. For example if you don't want to
visualize networks where two nodes are only connected to each other and not
anyone else you can:twarc2 network tweets.jsonl tweets.html --min-component-size 3It's less common but you can also remove nodes that are part of too large
subgraphs. For example if you wanted to remove any components that were
larger than 10:twarc2 network tweets.jsonl tweets.html --max-component-size 10AttributesThe possible node attributes are the following:screen_name:
When the node is a user, its username;
by default, it is used as the label of the nodes.
When the node is a tweet, the username of its author.user_id:
When the node is a user, its id;
if you want to use it as the label of the nodes,
you can use the flag--id-as-label.
When the node is a tweet, the id of its author.start_date:
The date of the first interaction that made the node appear in the graph.
For example, if the node is a retweet, it is its date of creation.
Or if the node is an original tweet,
it is the date of the first retweet, reply or quote.
The format isdd/mm/yyyy hh:mm:ss.The possible edge attributes are the following:type: When the nodes are tweets, one of the following values:retweet,replyorquote.retweet: When the nodes are users,
the number of retweets the source has made to the target.reply: When the nodes are users,
the number of replies the source has made to the target.quote: When the nodes are users,
the number of quotes the source has made to the target.mention: When the nodes are users,
the number of mentions the source has made to the target.weight:
When the nodes are users, the sum ofretweet,reply,quoteandmention.
When the nodes are hashtags,
the number of tweets that contained both hashtags.