Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
theo_vent
New Member

Issue - WordCloud with R

Hi everyone,

 

I'm trying to get a WordCloud appear on Power BI with an R-script. The script works fine with R, but when I plug it into Power BI and have my data already entered (import .csv file), I get this error message:

 

Error in strwidth(words[i], cex = size[i], ... : value 'cex' incorrect

Calls: wordcloud -> strwidth

 

The WordCloud works fine when I import my data with the R scrpit (text <- readLines(file.choose())) but not when I import my data before running R in Power BI.

 

Here is my script:

 

library("NLP")
library("methods")
library("tm") # main package for text mining
library("SnowballC") # package for stemming
library("RColorBrewer")
library("wordcloud") # package for WordCloud
library("proto")
library("gsubfn")
library("reshape2")
library("ngram")
library("tau")

 

text <- readLines(dataset)

## SEARCH FILE IN DOCUMENTS: ##
## text <- readLines(file.choose())


myCorpus <- Corpus(VectorSource(text))

myCorpus <- tm_map(myCorpus, tolower)
myCorpus <- tm_map(myCorpus, removePunctuation)
myCorpus <- tm_map(myCorpus, removeNumbers)
myCorpus <- tm_map(myCorpus, removeWords, stopwords("english"))

 

bigrams = textcnt(myCorpus, n = 2, method = "string")

bigrams = bigrams[order(bigrams, decreasing = TRUE)]

myDTM = TermDocumentMatrix(myCorpus, control = list(minWordLength = 1))

 

m = as.matrix(myDTM)

v = bigrams

d <- data.frame(word = names(v),freq=v)

 

set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 5,
          max.words=2000, random.order=FALSE, strwidth=50, strheight=0.5, rot.per=0.35,
          colors=brewer.pal(8, "Dark2"))

Can anyone tell me what I'm doing wrong ?

 

Thanks in advance,

 

Theo

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@theo_vent,

 

You may check the data frame d first. Besides, take a look at custom visual Word Cloud.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.