knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This document introduces you to rtweetlytics and it's functions, and shows you how to apply them. Once you’ve installed, read vignette("Introduction to rtweetlytics")
to learn more.
This document introduces you to the rtweetlytics package and all the functions inside it. Here to explore the package we have used data fetched from twitter as an example through get_store()
function. Once you have installed the package read vignette("Introduction to rtweetlytics")
to learn more about it.
To get access to the Twitter API and collect and store data in the form of csv, we will use functions from rtweetlytics
The goal of rtweetlytics is to extract and analyze tweet and finally create meaningful plot. It provides functions to download and store data, clean tweets, analyze tweets and create plot.
The package is an assimilation of four independent functions:
get_store()
: Extract data from twitter through calling API and provide csv file as output and create a dataframe.
clean_tweets()
: Cleans the text in the tweets and returns as new columns in the dataframe. The cleaning process includes converting into lower case, removal of punctuation, hastags and hastag counts.
analytics()
: Analyze the clean data frame extracted from twitter website, and returns a tibble including metrics of analytics.
plotting()
: The plotting function creates a bar-chart plot of most occurring hashtags.
library(rtweetlytics)
The first function in our library is the rtweetlytics::get_store()
. This function will require tghe developer to obtain bearer token from the twitter API development website.
tweets = rtweetlytics::get_store( bearer_token, keyword="vancouver", start_date="2022-01-12", end_date="2022-01-17") head(tweets)
tweets <- read.csv("../output/tweets_response.csv") head(tweets,2)
The second function in our library is the rtweetlytics::clean_tweets()
. This function cleans the data to gets tweet texts, word counts.
PATH <- "../output/tweets_response.csv" tweets_df <- rtweetlytics::clean_tweets(PATH, tokenization=TRUE, word_count=TRUE) head(tweets_df)
clean_tweets <- read.csv("../output/clean_tweets.csv") head(clean_tweets,2)
Our third function rtweetlytics::analytic()
analyses the data to give a resulting dataframe showing total Number of Likes, total Number of Comments, total Number of Retweets, percentage of Positive Sentiments, percentage of Neutral Sentiments, and percentage of Negative Sentiments.
results <- rtweetlytics::analytics(tweets_df) head(results)
knitr::include_graphics("../man/figures/analytics.png")
In the last and final function we are using rtweetlytics::plotting()
to further clean the data to extract hastags and plot the top 15 tags.
hash_plot <- rtweetlytics::plotting(tweets_df, text) hash_plot
knitr::include_graphics("../man/figures/plotting.png")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.