user3621202
user3621202

Reputation: 197

Plot output "looks" different in R vs RStudio

Am a newb to R. I tested some code to produce a word cloud. The code works. What is weird is that the output plot "looks" totally different when I run it in R vs RStudio. Ironically in R the output looks really nice. In RStudio it is not.

I dont think its the code and suspect it has something to do with RStudio settings.

Any suggestions?

cname <- file.path("", "corpus")
library (tm)
docs <- Corpus(DirSource(cname))

library (SnowballC)

for (j in seq(docs)) {
    docs[[j]] <- gsub("/"," ",docs[[j]])
    docs[[j]] <- gsub("@"," ",docs[[j]])}

docs <- tm_map(docs,tolower)
docs <- tm_map(docs, removeWords, stopwords("english"))
docs <- tm_map(docs, removeNumbers)
docs <- tm_map(docs, removePunctuation)
docs <- tm_map(docs, stripWhitespace)
dtm <- DocumentTermMatrix(docs)

library(wordcloud)
m <- as.matrix(dtm)
v <- sort(colSums(m),decreasing=TRUE)
head(v,14)
words <- names(v)
d <- data.frame(word=words, freq=v)
wordcloud(d$word,d$freq,min.freq=2)

Here are the two different images ... naturally there is some randomness due to the word cloud - that's not my problem - but the layouts "look" pretty different. The R one is more flowing. The R Studio one looks odd with words on top of each other.

output using R

output using R Studio

Upvotes: 1

Views: 1653

Answers (1)

Livius
Livius

Reputation: 3388

Have you tried clicking "zoom" in the RStudio preview pane? The size of the preview pane is used to set certain (default) graphical parameters, which is why the plot looks squished in comparison to the vanilla R plot. If you're outputting directly to file, you can also set size parameters in the respective commands (pdf(), png(), etc.)

Upvotes: 3

Related Questions