knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
An R package to extract twitter data, analyzed and plot top occuring hashtags
The goal of rtweetlytics is to extract, analyze and plot twitter data. It provides functions to extract twitter data, clean tweets, analyze tweets and plot hashtags frequency.
| Function Name | Input | Output | Description |
|----------------|----------------------------------------------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------|
| get_store() | bearer_token
, keyword
, start_date
, end_date
| Dataframe | Extract twitter data and save as .csv
|
| clean_tweets() | PATH
, | String | 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() | .csv
| Dataframe | Analyze the clean data frame extracted from twitter website, and returns a tibble including metrics of analytics. |
| plotting() | .csv
, col_text
| Image | The plotting function creates a bar-chart plot of most occurring hashtags.
The development version of rtweetlytics can be installed from GitHub with:
# install.packages("devtools") devtools::install_github("UBC-MDS/rtweetlytics")
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")
The names of core development team is listed below.
| Name | GitHub Handle | |:-----------------------:|:-----------------:| | Mahsa Sarafrazi | @mahsasarafrazi | | Shiva Shankar Jena | @shivajena | | Amir Shojakhani | @amirshoja | | Mahmoodur Rahman | @mahm00d27 |
Please note that this project is released with a Code of Conduct. By contributing to this project, one implies to agree to abide by its terms.
rtweetlytics
is licensed under the terms of the MIT license.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.