-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWordCloud.R
69 lines (52 loc) · 1.85 KB
/
WordCloud.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
library(readr)
questionposts_MO <- read_csv("~/OneDrive - Southeast Missouri State University/Spring2023/Data Fest 2023/Data/questionposts_MO.csv")
table(questionposts_MO$Category)
library(dplyr)
Financial <- questionposts_MO %>%
filter(Category == "Consumer Financial Questions")
FamilyChildren <- questionposts_MO %>%
filter(Category == "Family and Children")
IndividualRights <- questionposts_MO %>%
filter(Category == "Individual Rights")
Other <- questionposts_MO %>%
filter(Category == "Other")
Education <- questionposts_MO %>%
filter(Category == "Education")
HealthDisability <- questionposts_MO %>%
filter(Category == "Health and Disability")
IncomeMaintenance <- questionposts_MO %>%
filter(Category == "Income Maintenance")
Juvenile <- questionposts_MO %>%
filter(Category == "Juvenile")
WorkRelated <- questionposts_MO %>%
filter(Category == "Work, Employment and Unemployment")
HousingHomelessness <- questionposts_MO %>%
filter(Category == "Housing and Homelessness")
library(tidytext)
data(stop_words)
library(tm)
clean_tx<-function(data){
data(stop_words)
b <- tolower(data) # Convert the text to lowercase
c <- removeWords(b, stop_words$word) # Remove stop words
d <- gsub('[[:punct:]]+', ' ', c) # Remove punctuation
#e<-str_split(d," ")
x<-unlist(d)
return(x)
}
x<-sapply(Other$PostText,clean_tx)
x <- VectorSource(x)
x <- VCorpus(x)
dtm <- TermDocumentMatrix(x)
m <- as.matrix(dtm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
d <- d %>%
filter(word != "attorney" & word != "lawyer" & word != "court" & word != "missouri" & word != "legal")
#install.packages("wordcloud")
#library(wordcloud)
library(ggplot2)
wordcloud(words = d$word, freq = d$freq, min.freq = 5,scale=c(3.5,.2),
max.words=150, random.order=FALSE, rot.per=0.30,
colors=brewer.pal(8, "Dark2"))
mtext("title", side=1)