| Title: | Disaster Alert and Sentiment Analysis |
|---|---|
| Description: | By systematically aggregating and processing textual reports from earthquakes, floods, storms, wildfires, and other natural disasters, the framework enables a holistic assessment of crisis narratives. Intelligent cleaning and normalization techniques transform raw commentary into structured data, ensuring precise extraction of disaster-specific insights. Collective sentiments of affected communities are quantitatively scored and qualitatively categorized, providing a multifaceted view of societal responses under duress. Interactive geographic maps and temporal charts illustrate the evolution and spatial dispersion of emotional reactions and impact indicators. |
| Authors: | Hossein Hassani [aut], Nadejda Komendantova [aut], Leila Marvian Mashhad [aut, cre] |
| Maintainer: | Leila Marvian Mashhad <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.0 |
| Built: | 2026-05-28 08:41:05 UTC |
| Source: | https://github.com/cran/DisasterAlert |
It performs sentiment analysis on disaster-related text data using multiple methods.
analyze_disaster_sentiment(data, text_column = "User_Comment", method = "afinn")analyze_disaster_sentiment(data, text_column = "User_Comment", method = "afinn")
data |
A data frame containing disaster data |
text_column |
Name of the column containing text to analyze (default: "User_Comment") |
method |
Sentiment analysis method: "afinn", "bing", "nrc", or "syuzhet" (default: "afinn") |
Data frame with added sentiment scores and categories.
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
tweets_df <- data.frame( User_Comment = c( "The earthquake was terrible and scary", "Rescue teams are doing a wonderful job, I feel hopeful", "No damage here, everything feels normal" ), stringsAsFactors = FALSE ) result_df <- analyze_disaster_sentiment(tweets_df, text_column = "User_Comment", method = "afinn") print(result_df)tweets_df <- data.frame( User_Comment = c( "The earthquake was terrible and scary", "Rescue teams are doing a wonderful job, I feel hopeful", "No damage here, everything feels normal" ), stringsAsFactors = FALSE ) result_df <- analyze_disaster_sentiment(tweets_df, text_column = "User_Comment", method = "afinn") print(result_df)
This function calculates comprehensive statistics for sentiment analysis.
calculate_sentiment_stats(data)calculate_sentiment_stats(data)
data |
A data.frame with sentiment analysis results. |
List of statistical summaries.
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
result_df <- data.frame( User_Comment = c( "The earthquake was terrible and scary", "Rescue teams are doing a wonderful job, I feel hopeful", "No damage here, everything feels normal" ), sentiment_score = c(-2.5, 3.0, -0.5), sentiment_category = c("Negative", "Positive", "Neutral"), stringsAsFactors = FALSE ) stats <- calculate_sentiment_stats(result_df) str(stats) print("=== Overall Sentiment ===") print(stats$overall_sentiment) print("=== Extreme Comments ===") print(stats$extreme_comments) print("=== Summary Counts ===") print(stats$summary)result_df <- data.frame( User_Comment = c( "The earthquake was terrible and scary", "Rescue teams are doing a wonderful job, I feel hopeful", "No damage here, everything feels normal" ), sentiment_score = c(-2.5, 3.0, -0.5), sentiment_category = c("Negative", "Positive", "Neutral"), stringsAsFactors = FALSE ) stats <- calculate_sentiment_stats(result_df) str(stats) print("=== Overall Sentiment ===") print(stats$overall_sentiment) print("=== Extreme Comments ===") print(stats$extreme_comments) print("=== Summary Counts ===") print(stats$summary)
It cleans and preprocesses text data for analysis.
clean_disaster_text(text)clean_disaster_text(text)
text |
Vector of text strings to clean |
Vector of cleaned text strings.
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
raw_comments <- c( "The earthquake!!! happened @ midnight...", NA, "Floods in 2025 were terrible? Really scary.", "Support & rescue teams: amazing work!" ) cleaned_comments <- clean_disaster_text(raw_comments) print(cleaned_comments)raw_comments <- c( "The earthquake!!! happened @ midnight...", NA, "Floods in 2025 were terrible? Really scary.", "Support & rescue teams: amazing work!" ) cleaned_comments <- clean_disaster_text(raw_comments) print(cleaned_comments)
This function creates interactive plots using plotly for better user experience.
create_interactive_plots(data, plot_type = "scatter")create_interactive_plots(data, plot_type = "scatter")
data |
A data.frame with sentiment analysis results |
plot_type |
Type of interactive plot: "scatter", "bar", "timeline" |
Plotly object.
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
sample_data <- data.frame( City = c("CityA", "CityB", "CityA", "CityC", "CityB"), Longitude = c(10.0, 11.5, 10.0, 12.2, 11.5), Latitude = c(50.1, 49.9, 50.1, 50.5, 49.9), sentiment_score = c( 2.5, -1.0, 0.0, 3.0, -2.0), sentiment_category= c("Positive","Negative","Neutral","Positive","Negative"), User_Comment = c( "Amazing rescue efforts!", "Terrible flooding last night.", "All calm here.", "Hope everyone is safe.", "Worst disaster ever." ), Timestamp = as.POSIXct(c( "2025-07-10 14:00", "2025-07-10 15:30", "2025-07-11 10:00", "2025-07-11 12:45", "2025-07-12 09:20" )) ) scatter_plot <- create_interactive_plots(sample_data, plot_type = "scatter") bar_plot <- create_interactive_plots(sample_data, plot_type = "bar") bar_plot timeline_plot <- create_interactive_plots(sample_data, plot_type = "timeline") timeline_plotsample_data <- data.frame( City = c("CityA", "CityB", "CityA", "CityC", "CityB"), Longitude = c(10.0, 11.5, 10.0, 12.2, 11.5), Latitude = c(50.1, 49.9, 50.1, 50.5, 49.9), sentiment_score = c( 2.5, -1.0, 0.0, 3.0, -2.0), sentiment_category= c("Positive","Negative","Neutral","Positive","Negative"), User_Comment = c( "Amazing rescue efforts!", "Terrible flooding last night.", "All calm here.", "Hope everyone is safe.", "Worst disaster ever." ), Timestamp = as.POSIXct(c( "2025-07-10 14:00", "2025-07-10 15:30", "2025-07-11 10:00", "2025-07-11 12:45", "2025-07-12 09:20" )) ) scatter_plot <- create_interactive_plots(sample_data, plot_type = "scatter") bar_plot <- create_interactive_plots(sample_data, plot_type = "bar") bar_plot timeline_plot <- create_interactive_plots(sample_data, plot_type = "timeline") timeline_plot
This function creates an interactive Leaflet map showing disaster locations colored by sentiment.
create_sentiment_map(data, lat_col = "Latitude", lon_col = "Longitude")create_sentiment_map(data, lat_col = "Latitude", lon_col = "Longitude")
data |
A data.frame with sentiment analysis results |
lat_col |
Name of latitude column (default: "Latitude") |
lon_col |
Name of longitude column (default: "Longitude") |
Leaflet map object
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
sample_data <- data.frame( City = c("CityA", "CityB", "CityC"), Longitude = c(10.0, 11.5, 12.2), Latitude = c(50.1, 49.9, 50.5), sentiment_score = c( 2.5, -1.0, 0.0), sentiment_category = c("Positive", "Negative", "Neutral"), User_Comment = c( "Amazing rescue efforts!", "Terrible flooding last night.", "All calm here." ), stringsAsFactors = FALSE ) sentiment_map <- create_sentiment_map(sample_data, lat_col = "Latitude", lon_col = "Longitude") sentiment_mapsample_data <- data.frame( City = c("CityA", "CityB", "CityC"), Longitude = c(10.0, 11.5, 12.2), Latitude = c(50.1, 49.9, 50.5), sentiment_score = c( 2.5, -1.0, 0.0), sentiment_category = c("Positive", "Negative", "Neutral"), User_Comment = c( "Amazing rescue efforts!", "Terrible flooding last night.", "All calm here." ), stringsAsFactors = FALSE ) sentiment_map <- create_sentiment_map(sample_data, lat_col = "Latitude", lon_col = "Longitude") sentiment_map
This function Generates synthetic tweets with weather conditions and sentiment.
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
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
tweets <- generate_tweets(100) head(tweets)tweets <- generate_tweets(100) head(tweets)
This function Creates and plots a word cloud based on the cleaned and stemmed words extracted from one or more tweets.
generate_word_clouds(tweet)generate_word_clouds(tweet)
tweet |
A character vector of tweet texts, or a data frame/tibble whose first column contains tweet texts. |
The main side effect is the word cloud drawing.
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
# Generate word cloud from a single tweet tweet_text <- "This is a sample tweet for word cloud generation!" generate_word_clouds(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!" generate_word_clouds(tweet_text) ## This will generate a word cloud image where the most frequent words ## in the tweet will be displayed larger.
This function Creates various plots showing sentiment distribution.
plot_sentiment_distribution(data, plot_type = "bar")plot_sentiment_distribution(data, plot_type = "bar")
data |
A data frame with sentiment analysis results |
plot_type |
Type of plot: "pie", "bar", "histogram", or "geographic" |
ggplot object or plot.
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
sample_data <- data.frame( sentiment_score = c( 2.5, -1.0, 0.0, 3.0, -2.0, 1.5, -0.7), sentiment_category = c("Positive", "Negative", "Neutral", "Positive", "Negative", "Positive", "Neutral"), Longitude = c(10.0, 11.5, 10.0, 12.2, 11.5, 10.8, 12.0), Latitude = c(50.1, 49.9, 50.1, 50.5, 49.9, 50.3, 50.4), stringsAsFactors = FALSE ) bar_plot <- plot_sentiment_distribution(sample_data, plot_type = "bar") print(bar_plot) hist_plot <- plot_sentiment_distribution(sample_data, plot_type = "histogram") print(hist_plot) plot_sentiment_distribution(sample_data, plot_type = "pie") geo_plot <- plot_sentiment_distribution(sample_data, plot_type = "geographic") print(geo_plot)sample_data <- data.frame( sentiment_score = c( 2.5, -1.0, 0.0, 3.0, -2.0, 1.5, -0.7), sentiment_category = c("Positive", "Negative", "Neutral", "Positive", "Negative", "Positive", "Neutral"), Longitude = c(10.0, 11.5, 10.0, 12.2, 11.5, 10.8, 12.0), Latitude = c(50.1, 49.9, 50.1, 50.5, 49.9, 50.3, 50.4), stringsAsFactors = FALSE ) bar_plot <- plot_sentiment_distribution(sample_data, plot_type = "bar") print(bar_plot) hist_plot <- plot_sentiment_distribution(sample_data, plot_type = "histogram") print(hist_plot) plot_sentiment_distribution(sample_data, plot_type = "pie") geo_plot <- plot_sentiment_distribution(sample_data, plot_type = "geographic") print(geo_plot)
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.
Hossein Hassani and Leila Marvian Mashhad and Nadejda Komendantova.
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)