I have the following categorical data set, which is a survey data. I am trying to visualize the text survey data.
I have created a corpus
but I did not got my result as it is taking each row individually. I would like to take each fruit seperately.
Code to create corpus
library(wordcloud)
library(tm)
corpus = Corpus(VectorSource(t1$Column))
set.seed(100)
wordcloud(words=dat$word, freq=dat$freq, random.order=FALSE)
The following code chunk plots a graph that may fit to your data:
# setup environment
library(ggplot2)
library(plyr)
library(stringr)
# define dataframe
df = data.frame(
id = 1:6,
column = c('apple', 'apple, banana', 'pineapple, Cherry',
'Cherry, Apple, Banana', 'Banana, Cherry', 'Apple, Cherry')
)
# split cells containing more than one fruit
fruits = str_split(df$column, ', ')
# bind fruits into a dataframe
fruits = do.call(rbind, lapply(fruits, as.data.frame))
fruits[[1]] = str_to_title(fruits[[1]])
names(fruits) = 'column'
# plot
ggplot(fruits) +
geom_bar(aes(x = column)) +
coord_flip() +
labs(y = 'Count') +
theme(axis.title.y = element_blank())
Here is the output: