MENU

Fun & Interesting

Text Visualization in R Studio: GGPLOT and WORD CLOUD

Anita Mendiratta 1,304 lượt xem 2 weeks ago
Video Not Working? Fix It Now

Learn how to analyze and visualize text data in RStudio using popular packages like tidytext, dplyr, ggplot2, and wordcloud. This tutorial shows how to turn plain text into powerful visuals including word frequency plots and interactive word clouds.

📦 Step 1: Load your dataset and install packages

myanalysis <- read.csv("file:///D:/Textual_analysis.csv")

install.packages("tidytext")
install.packages("dplyr")

library(tidytext)
library(dplyr)
🧹 Step 2: Clean and process the text data

myanalysis_wf<- myanalysis %⋗%
unnest_tokens(word, text) %⋗%
anti_join(stop_words, by = "word") %⋗%
count(word, sort = TRUE)

myanalysis_wf
📊 Step 3: Visualize word frequencies using ggplot2

library(ggplot2)

# Basic point plot
ggplot(myanalysis_wf) + geom_point(aes(word, n))

# Ordered and flipped plot
ggplot(myanalysis_wf) + geom_point(aes(reorder(word, n), n)) + coord_flip() + labs(title = "Words with Frequency", x = "Words", y = "N")

# Top 2 words only
ggplot(myanalysis_wf %⋗% top_n(2)) + geom_point(aes(reorder(word, n), n)) +
coord_flip() + labs(title = "Top 2 Words", x = "Words", y = "N")

☁️ Step 4: Create word clouds
install.packages("wordcloud")
library(wordcloud)
library(tm)

wordcloud(words = myanalysis_wf$word, freq = myanalysis_wf$n, min.freq = 1,
max.words = 50, random.order = FALSE, rot.per = 0.3,
colors = brewer.pal(8, "Dark2"))

install.packages("wordcloud2")
library(wordcloud2)

# Basic word cloud
wordcloud2(data = myanalysis_wf)

# Custom size and shape
wordcloud2(data = myanalysis_wf, size = 0.3, shape = 'circle')


Please note that YouTube does not allow angled brackets in video descriptions. Therefore, I have used the Unicode large < and ⋗ symbol as a replacement.")


🧠 Concepts: Text Mining, Data Cleaning, Word Frequency, Word Cloud, Visualization in R
🔔 Subscribe for more R tutorials, text analysis, and data science projects!

#RStudio #ggplot2 #wordcloud #TextAnalysis #tidytext #dplyr #DataScience #RStats #NLP

Comment