Hi,
I am executing below code to generate word cloud in BI tool but getting error.
code is:
library(tm)
library(wordcloud)
#############################################################################
# Convert The Input column col1 to a single vector
myinput <- do.call(paste, c(as.list(col1), sep=" "))
#############################################################################
# Create a Corpus from the newly created vector myinput
# A Corpus is a collection of texts http://en.wikipedia.org/wiki/Text_corpus
b=Corpus(VectorSource(myinput), readerControl = list(language = 'eng'))
#############################################################################
# Do some cleaning of the Corpus, lowercase, remove stop words etc.
b<- tm_map(b, content_transformer(tolower)) #Changes case to lower case
b<- tm_map(b, stripWhitespace) #Strips White Space
b <- tm_map(b, removePunctuation) #Removes Punctuation
b <- tm_map(b, removeWords, stopwords('english')) #Removes Stop Words
#############################################################################
# Convert the Corpus to a DataFrame and sort it for input to wordcloud
tdm <- TermDocumentMatrix(b)
m1 <- as.matrix(tdm)
v1<- sort(rowSums(m1),decreasing=TRUE)
d1<- data.frame(word = names(v1),freq=v1)
#############################################################################
# Set up colourings
pal <- brewer.pal(9, "BuGn")
pal2 <- brewer.pal(8,"Dark2")
#############################################################################
# Create png image
png('wordcloud.png', width=640,height=400)
#############################################################################
# Create the wordcloud
#wordcloud(d1$word,d1$freq,scale=c(8,.3),min.freq=2,max.words=100, random.order=T, rot.per=.15, colors=pal, vfont=c("sans serif","plain"))
wordcloud(d1$word,d1$freq, scale=c(8,3),min.freq=3,max.words=Inf, random.order=FALSE, rot.per=.15, colors=pal2)
dev.off()
#############################################################################
# Convert the png image to binary
img.width <- 600
img.height <- 500
img <- data.frame(r=readBin(file('wordcloud.png', open="rb"), what="raw", n=(file.info('wordcloud.png')$size)))
return(img)
errors are :
** 1.
'Error in data.frame(r = readBin(file("wordcloud.png", open = "rb"), w : cannot open the connection 'wordcloud.png'
eval(expr, envir, enclos)
eval(expr, envir, enclos)
'Error in wordcloud(d1$word, d1$freq, scale = c(8, 3), min.freq = 3, m : argument is of length zero
eval(expr, envir, enclos)
eval(expr, envir, enclos)
wordcloud(d1$word, d1$freq, scale = c(8, 3), min.freq = 3,'.
`
any idea pls