Title: | Comprehensive Analysis of Tweet Sentiments and Weather Data |
---|---|
Description: | A comprehensive suite of functions for processing, analyzing, and visualizing textual data from tweets is offered. Users can clean tweets, analyze their sentiments, visualize data, and examine the correlation between sentiments and environmental data such as weather conditions. Main features include text processing, sentiment analysis, data visualization, correlation analysis, and synthetic data generation. Text processing involves cleaning and preparing tweets by removing textual noise and irrelevant words. Sentiment analysis extracts and accurately analyzes sentiments from tweet texts using advanced algorithms. Data visualization creates various charts like word clouds and sentiment polarity graphs for visual representation of data. Correlation analysis examines and calculates the correlation between tweet sentiments and environmental variables such as weather conditions. Additionally, random tweets can be generated for testing and evaluating the performance of analyses, empowering users to effectively analyze and interpret 'Twitter' data for research and commercial purposes. |
Authors: | Andriette Bekker [aut], Mohammad Arashi [aut], Leila Marvian Mashhad [aut, cre], Priyanka Nagar [aut] |
Maintainer: | Leila Marvian Mashhad <[email protected]> |
License: | GPL-3 |
Version: | 1.0 |
Built: | 2024-11-21 05:21:53 UTC |
Source: | https://github.com/cran/WeatherSentiment |
This function calculates the Pearson correlation coefficient between sentiment scores extracted from tweets and a weather variable (e.g., temperature) in a merged dataset.
corr_analys(t, w, com_var = "Date", var1 = "T1", var2 = "T2")
corr_analys(t, w, com_var = "Date", var1 = "T1", var2 = "T2")
t |
A data.frame containing tweets with a 'text' column |
w |
A data.frame containing weather data with a column matching the 'com_var' |
com_var |
The name of the common variable for merging the tweet and weather data. Defaults to "Date". |
var1 |
The name of the column in 't' containing the tweet text. Defaults to "T1". |
var2 |
The name of the column in 'w' containing the weather variable. Defaults to "T2". |
The Pearson correlation coefficient between sentiment scores and the weather variable.
Leila Marvian Mashhad and Andriette Bekker and Mohammad Arashi and Priyanka Nagar.
Date1 <- c('2024-01-01', '2024-01-02') T1 <- c('I love sunny days', 'Rainy days are the worst') tweet <- data.frame(Date = Date1 , T1 = T1) weather <- data.frame(Date = Date1, T2 = c(25, 15)) cor1 <- corr_analys(tweet, weather, com_var = "Date", var1 = "T1", var2 = "T2") print(cor1)
Date1 <- c('2024-01-01', '2024-01-02') T1 <- c('I love sunny days', 'Rainy days are the worst') tweet <- data.frame(Date = Date1 , T1 = T1) weather <- data.frame(Date = Date1, T2 = c(25, 15)) cor1 <- corr_analys(tweet, weather, com_var = "Date", var1 = "T1", var2 = "T2") print(cor1)
This function generates n random tweets about the weather. Each tweet consists of a randomly selected positive or negative phrase about a randomly selected weather condition.
generate_tweets(n)
generate_tweets(n)
n |
The number of tweets to generate |
A data.frame containing two columns: Date: The date of the tweet T1: The text of the tweet
Leila Marvian Mashhad and Andriette Bekker and Mohammad Arashi and Priyanka Nagar.
tweets <- generate_tweets(10) print(tweets)
tweets <- generate_tweets(10) print(tweets)
This function takes a list of tweets as input and performs various preprocessing steps to prepare the data for sentiment analysis.
process_tweet(tweet)
process_tweet(tweet)
tweet |
A vector of tweets |
A list including:
A vector containing preprocessed tweets.
A vector containing tokens of tweets.
Leila Marvian Mashhad and Andriette Bekker and Mohammad Arashi and Priyanka Nagar.
tweets_data <- "I'm feeling really happy today! #goodvibes" preprocessed_tweets <- process_tweet(tweets_data) print(preprocessed_tweets)
tweets_data <- "I'm feeling really happy today! #goodvibes" preprocessed_tweets <- process_tweet(tweets_data) print(preprocessed_tweets)
This function analyzes the sentiment of a tweet and returns the sentiment score and the text of the tweet.
sentiment_analys(tweet)
sentiment_analys(tweet)
tweet |
A character string containing the text of the tweet |
A data.frame containing two columns: text: The text of the tweet ave_sentiment: The sentiment score of the tweet In addition, it presents a plot to effectively visualize the spectrum of human emotions.
Leila Marvian Mashhad and Andriette Bekker and Mohammad Arashi and Priyanka Nagar.
#Example 1 tweet_text <- "I love R!" sentiment_result <- sentiment_analys(tweet_text) print(sentiment_result) #Example2 tweets <- c("I hate R!", "R is a great language!", "R is difficult to learn!") sentiment_results <- sapply(tweets, sentiment_analys) print(sentiment_results)
#Example 1 tweet_text <- "I love R!" sentiment_result <- sentiment_analys(tweet_text) print(sentiment_result) #Example2 tweets <- c("I hate R!", "R is a great language!", "R is difficult to learn!") sentiment_results <- sapply(tweets, sentiment_analys) print(sentiment_results)
This function takes a tweet text as input and performs sentiment analysis to visualize its overall sentiment polarity.
sentiment_polarity(tweet)
sentiment_polarity(tweet)
tweet |
A character vector containing the tweet text. |
A ggplot object displaying a bar chart with sentiment polarity (positive/negative) on the x-axis and sentiment score on the y-axis.
Leila Marvian Mashhad and Andriette Bekker and Mohammad Arashi and Priyanka Nagar.
e <- c("The rain is ruining my outdoor plans today.", "I love the sunny weather today!") s1 <- sentiment_polarity(e) print(s1)
e <- c("The rain is ruining my outdoor plans today.", "I love the sunny weather today!") s1 <- sentiment_polarity(e) print(s1)
This function generates a word cloud visualization of the most frequent words in a tweet after basic cleaning. Stop words and words less than 3 characters are removed.
word_cloud_tweet(tweet)
word_cloud_tweet(tweet)
tweet |
A character string containing the text of the tweet. |
void (generates a word cloud image).
Leila Marvian Mashhad and Andriette Bekker and Mohammad Arashi and Priyanka Nagar.
# Generate word cloud from a single tweet tweet_text <- "This is a sample tweet for word cloud generation!" word_cloud_tweet(tweet_text) ## This will generate a word cloud image where the most frequent words ## in the tweet will be displayed larger.
# Generate word cloud from a single tweet tweet_text <- "This is a sample tweet for word cloud generation!" word_cloud_tweet(tweet_text) ## This will generate a word cloud image where the most frequent words ## in the tweet will be displayed larger.