wordcloud2 in R with figPath - r

I am working on a word cloud shaped by an image on a jpg or png file. I am using R and its wordcloud2 package with figPath option.
Issuing the following command:
wordcloud2(Word_more_freq,figPath = "unicorno.jpg",size = 1.5, color = "skyblue"),
where Word_more_freq is a data frame and its columns are words and freq (words' frequency), sometimes no image is displayed and other times I can just view the image without the words. No error message is raised.
Could you help me please?
Thanks in advance.
Cheers,
Francesco

Related

Wordcloud showing image but not words in R

Having trouble getting the words to show up on an image mask for a word cloud in R.
Using this Simpsons PNG (https://imgbin.com/png/PV5MuKbG/lisa-simpson-bart-simpson-homer-simpson-maggie-simpson-mayor-quimby-png)
Code is below:
wc1 <- sort(table(bplot_one$word), decreasing = TRUE)
figPath <- "Simpsons.png"
wordcloud2(wc1, figPath = figPath)
It executed fine, but all I get is the png without the words
Any idea how to fix this?
Thanks
This is listed as an open issue on the package site: Fig Mask and lettercloud are not working with package installed from github #68. There is a workaround posted: mask and letterCloud silently fail #12.
The workaround is to refresh the viewer or open in a browser.

Worcloud2 returns blank image instead of desired output

I am currently trying to use the library wordcloud2 from R to do a project for my university.
I am following the instructions of cran.
I have managed to do the basic tasks
library(wordcloud2)
library(devtools)
wordcloud2(data = demoFreq)
wordcloud2(demoFreq, color = "random-light", backgroundColor = "grey")
however, if I try something more complex, like trying to add a logo
wordcloud2(demoFreq, figPath = "logo.png", size = 1.5,color = "skyblue")
the program returns the image without the word cloud on it (the logo is in the same folder as the R code)
letterCloud(demoFreq, word = "R", size = 2)
does not return anything at all.
I don't know what is wrong with my code, since I am copying the exact instructions of the webpage. Can someone please help me?
I had a similar issue, using wordcloud2 with flexdashboard. In that cas I solved installing version 0.2.2 of wordcloud2, from github, instead of 0.2.1 from CRAN: 'devtools::install_github("lchiffon/wordcloud2")'.

can't save plots (wordcloud package) to images in R using png(), dev.off()? [duplicate]

This question already has an answer here:
Is there any way to show a wordcloud2 in Rmarkdown as a PDF or Word file?
(1 answer)
Closed 3 years ago.
Can you please help to save word cloud on my local drive as an image?, I am looking for a code/command to get it done automatically through R Programming. I have tried with saveWidget, plotly, orca but not get success.
I have used below code to create the word cloud.
library(wordcloud2)
wordcloud2(demoFreqC, figPath = figPath,color = "orangered",fontFamily = "Miso")
The procedure is outlined here. Briefly:
library(htmlwidgets)
install.packages("webshot")
webshot::install_phantomjs()
library(wordcloud2)
hw <- wordcloud2(demoFreq,size = 3)
saveWidget(hw,"1.html",selfcontained = F)
webshot::webshot("1.html","1.png",vwidth = 1992, vheight = 1744, delay =10)
If you are using RStudio, there is an option to import the output as image on the IDE itself.
in R studio there is an option to export the plot in JPG or PNG format with the image size you want.

R wordcloud2 showing blank page - persistent problem

I have the exact same problem as previously asked May 3 '18.
wordcloud2 performs fine until I try to add a mask. The code executes fine in RMarkdown with no error but also produces only a blank page.
Previous suggestions were to re-install wordcloud2 which I did. However, this did not resolve of the problem.
# works fine gives word cloud with red palette
wordcloud2(hmtTable,
size = 0.7,
color = rep_len(redPalette, nrow(hmtTable)))
# produces blank page, heart.png is in subdirectory figs
wordcloud2(hmtTable,
size = 1.5,
figPath = "figs/heart.png",
color = rep_len(redPalette, nrow(hmtTable)))
This code should have produced a word cloud in shape of mask shape. It did not, and no error message was given.

Weird lines appear in R graph after copying it "as metafile" to Word and exporting it as PDF

Journal in which I am submitting a research paper requires that article should be submitted in PDF-format. I am using R for statistics and graphs.
I have used basic formulas to print my graphs. barplot() for bar charts, boxplot() for boxplots and draw.triple.venn in VennDiagram package. I am not using special commands or formulas for device or graphical parameters.
I print my graphs in R and then copied them "as metafile" to produce high quality graphs.
When i attach these graphs in R they appear just fine. However, when I print my work as PDF in Word these lines appear to graphs.
Example for the first graph:
venn.plot <- draw.triple.venn(45, 34, 32,
14, 5, 11, 3, c(sprintf("Elevated\nWB Cr and Co"), sprintf("Mixed or\nsolid PT"), sprintf("Moderate to severe\ng.minimus atrophy")),
lwd = 4,
lty = 'solid',
cex = 3.5,
fontface = "bold",
fontfamily = "sans",
cat.cex = 1.8,
cat.fontface = "bold",
cat.default.pos = "outer",
cat.pos = c(-20, 20, 180),
cat.dist = c(0.115, 0.115, 0.095),
cat.fontfamily = "sans",
rotation = 1
);
Example for the second:
boxplot(df$Crmri~df$gmed2,log="y",yaxt="n",ylim=c(0.3,200));
axis(2,at=c(0,1,2,10,20,100),labels=c("0 ppb","1 ppb","2 ppb","10 ppb","20 ppb","100 ppb"),las=2);
I have several barplots in Word file and after saving as PDF these graphs are just fine.
At first I tried to save those graphs as metafile in R and adding them to Word after but the lines still appear. If I open my EMF-files in any other Viewer those lines are not there.
Any ideas? Thanks!
This has been discussed on r-help before. See:
https://stat.ethz.ch/pipermail/r-help/2011-September/289705.html
Seems to be due to the way Word converts documents to PDFs when you use "Save As" and then choose PDF.
If you have Acrobat (not just the reader), printing the document via the Adobe PDF "printer" should get rid of the lines. Otherwise, you may have to consider switching to another graphics format (e.g., png).
There's a new package export that just came out on CRAN that allows you to export graphs to Powerpoint or Word in native Office format. From there you can then save as PDF in Office without problems, without any weird lines appearing, see
https://cran.r-project.org/web/packages/export/index.html and
https://github.com/tomwenseleers/export
E.g.
install.packages("export")
library(export)
boxplot(count ~ spray, data = InsectSprays, las = 2)
graph2doc(file="plot.docx", width=7, height=5)
graph2ppt(file="plot.pptx", width=7, height=5)
Even after saving to PDF within Powerpoint this will give you a perfect quality vector format PDF without any weird lines :
Other advantage is that the Powerpoint version you get is fully editable vector format, enabling you to make any small required changes in the layout (it also fully supports transparency / alpha channels).
I can confirm that this issue still exists in Word for Office 365 and Word for Office 2016. Copying from R-Studio as a Metafile results in lines in the plots when you convert to PDF (using Word's Save as PDF function). Copying from R-Studio as a Bitmap or exporting as an image does not result in lines, but unfortunately the image quality in Word and PDF is not as clear as the Metafile. The response that described printing the document via the Adobe PDF Printer does avoid the lines, but I found that this approach loses the dynamic links in the text of the Word document (such as Table of Contents links). I have Adobe Acrobat Pro XI. So that solution does not work for me. In the end, the best solution I can find seems to be copying as a Bitmap. Unfortunately the image quality is not very good.

Resources