0
votes

Trying to get Tableau to display a simple R visual (word cloud) but I can't get it work. Any help would be appreciated.

R code:

library(wordcloud)
library(tm)
cp <- Corpus(VectorSource('asdf gato perro 98945')) 
wordcloud(cp)

The table calculation in Tableau looks like this:

SCRIPT_STR("library(wordcloud)
library(tm)
cp <- Corpus(VectorSource('asdf gfg ff 98945')) 
wordcloud(cp)",ATTR([SampleMeasure1]))

My question is how can I display the above word cloud without supplying a measure (SampleMeasure1)? Is it even possible to display an R word cloud in Tableau? If so could anyone please provide a simple example what the calculation should look like?Thank you

2

2 Answers

0
votes

I'm assuming your goal is simply to make a word cloud in Tableau from a vector you have in R?

I took the vector you suggested and produced a dataframe with random counts for each string in the vector. I saved the vector as a csv.

count <- as.integer(round(runif(4,1,100),0))
words <- c('asdf','gfg','ff','98945')
df <- as.data.frame(cbind(words,count),stringsAsFactors = FALSE)
df$count <- as.integer(df$count)
write.csv(df,"word_cloud.csv",row.names = FALSE)

Then if I import the csv to Tableau I can simply create a word cloud. The below image shows the Tableau configurations:

  • The "Word" needs to be put in the text bin.
  • The "Count" should be in the size bin.
  • **Then you have to flip the marks drop down menu to text. It will produce a word cloud. **

enter image description here

Alternatively you can use the wordcloud library as you're attempting to do. I used the Kaggle Starbucks data set for this example, found here. The code used to generate this image was:

library(wordcloud)
df <- read.csv("directory.csv",stringsAsFactors = FALSE)
words <- df$City
words <- gsub(" ",".",words)
wordcloud(words, min.freq = 50)

enter image description here

0
votes

R: Making a Word Cloud Graph (Words Graph) Simple

Suppose you have one table with words and related values like this one, named Top5 Top5 sheet

In order to get example produced by this code Do the following:

  1. Import the Top5 dataset

  2. Execute:

    install.packages("wordcloud") # word-cloud generator library("wordcloud") wordcloud(words = Top5$word, freq = Top5$value, min.freq = 1, max.words=200, random.order=FALSE, rot.per=0.2, colors=brewer.pal(8, "Dark2"))