i am trying to create function for making word cloud . and i want export it into word output while knitting it in chunks or rmrkdown
i have tried the below approach but its not working properly, i want to keep the same parameters
library(tm)
library(wordcloud2)
df <- data.frame(word=c("Total_power of the HR Dept","Total_power of the HR Dept",
"Total_power of the HR Dept","Total_power of the HR Dept",
"Total_power of the HR Dept; power of local houses","Apply through online process",
"Apply through online process; Hiring fresh hires","Assessment correlation with Work Performance and performance predicting",
"Assessment correlation with Work Performance and performance predicting","Benefit Benchmark",
"Benefit Benchmark","Benefit Benchmark",
"Collaboration with Education Sector","Compensation and Fleet offerings",
"Data on employable pool vs skills-based roles","DEI - Diversity Equity and Inclusion",
"Effectivity of employees' performance assessment","Employment availability at all sections",
"Employment availability at all sections","Employment availability at all sections",
"Employment availability at all sections","Employment availability at all sections",
"EVP","General HR rulings",
"power of local houses","power of local houses",
"power of local houses","management and social",
"ommision material","ommision material",
"moivated, partly different cost","sling material",
"recurring material","Retention; Engagement",
"Salary and benefits benchmarking","Salary and benefits benchmarking",
"self proclaimed","social distancing",
"social distancing","Strategic recruitment",
"trademarks of all th eplayers","Total market available",
"Try and tested","Try and tested"))
generate_wordcloud <- function(text_data, var, shape = 'square', footer_note = NULL) {
library(tm)
library(wordcloud2)
docs <- Corpus(VectorSource(text_data))
docs <- docs %>%
tm_map(removeNumbers) %>%
tm_map(removePunctuation) %>%
tm_map(stripWhitespace) %>%
tm_map(content_transformer(tolower)) %>%
tm_map(removeWords, stopwords("english"))
dtm <- TermDocumentMatrix(docs)
matrix <- as.matrix(dtm)
words <- sort(rowSums(matrix), decreasing = TRUE)
df <- data.frame(word = names(words), freq = words)
set.seed(1234)
wordcloud2(df, size = 0.5, shape = shape, minRotation = 0, maxRotation = 0)
if (!is.null(footer_note)) {
text_annotation(
df = df,
aes(label = footer_note),
x = "center",
y = "top",
xend = NULL,
yend = NULL,
align = NULL,
vjust = NULL,
hjust = NULL,
color = NULL,
size = NULL,
alpha = NULL
)
}
}
generate_wordcloud(df, var = "word", shape = 'square', footer_note = "Generated by My Word Cloud Function")