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.
Related
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.
I've been creating heatmaps using heatmap.2() in R.
I'm using the viridis() color scale.
I used pdf() to create the output.
As you can see the color key looks different when viewing the PDF file using Adobe Acrobat (top panel) v. using Preview (bottom panel) in OS X (version 11.3.1). The Adobe Acrobat appearance is closer to what I expect. The colors in Preview appear washed out and undersaturated.
Has anyone else had this experience?
Code added after original post:
The following code generates the "washed out" color key in the heatmap:
library ('viridis')
library('gplots')
test.matrix <- matrix(ncol=25, nrow=9, -4:4)
breaks <- seq(-4,4,0.5)
pdf(file='heatmap.pdf', width=10, height=6)
heatmap.2(test.matrix, density.info = 'none', trace='none',
Colv = F, Rowv = F, dendrogram = 'none',
col=viridis(length(breaks)-1), breaks=breaks
)
dev.off()
Adobe Reader (default settings) does not display plots exactly as they are stored in the file. You can play around with the settings at Edit > Preferences > Page Display. Try to open the file with another PDF reader and you probably see a difference. The Adobe program also makes thin lines appear thicker, smoothes low resolution images, fills gaps between nearby lines etc.
Visual comment - not an answer for bounty.
As per Jon-Spring comment above.
It is not a difference per app as such, here is the exact same input file with colour profiles toggled on and off on the same screen. Note my simulation unlike the OP affects the Pixelated Text. I am using an RGB image from 1st example above rather than Coloured Objects However it shows the underlying difference.
I would thus suggest looking for any colour profile related settings in Preview
I want to create a wordcloud in R where the words are within the shape of a picture. A common example is to use the Twitter bird shape, as shown in Wordcloud with a specific shape.
Although I followed multiple tutorials, my code always results in an empty sheet. The standard visualization without the shape works fine.
library(wordcloud2)
library(RColorBrewer)
wordcloud2(demoFreq, size = 0.7, shape = 'star') # -> this works fine
#put picture in current working directory
getwd() #get current working directory
wordcloud2(demoFreq, figPath="heart.png", size = 1.5, color = "skyblue", backgroundColor="black") # -> this does not show anything
Heart image link i used. I installed the worldcloud2 from github master repo as I was troubleshooting, not sure if that helped or not. Nothing rendered for me until I added size=1 in the worldcloud2 function. I also saved the picture as .jpg
library(wordcloud2)
library(RColorBrewer)
#library(devtools)
#install_github("lchiffon/wordcloud2")
wordcloud2(demoFreq,size = 1,figPath = "heart.jpg")
I'm working on a composite graph in R, for which I export a ggplot and then load it into magick for further annotations and compositing another graph. Since alignment is a lot of trial and error, I will keep a version with all "final" annotations and use a second image to play around with.
Usually, this works pretty well, but from time to time either or both of two errors will happen:
The image turns into black/white (not even grayscale, just hard black/white)
Some of the annotations are being "skipped", meaning they just don't show up in the preview
I have tested the second error, and the sequence of commands matters. All annotations until a certain point will be applied and all thereafter won't.
The only thing that reliably "fixes" the error is restarting the PC. Restarting the R session, clearing the cache, restarting Rstudio remain without effect. Once this error has occurred, it will keep persisting (rerunning the code will produce the exact same result) until a system reboot.
A simplified version of what my code does:
graph1 <- image_read(path1)
graph2 <- image_read(path2)
annotated_graph <- graph1 %>% # creating a saved version so I don't have to run all of the code every time
image_border(color='white', geometry = '2000x1000') %>%
image_annotate("text1", size = 100, color = "black", location = "+1000+4000") %>%
image_annotate("text2", size = 100, color = "black", location = "+2000+4000")
annotated_graph %>% # opens current "experiment" state in viewer
image_annotate("text3", size = 100, color = "black", location = "+3000+4000") %>%
image_composite(image_scale(graph2, "1000"), offset = "+1000+1000")
To test if the viewer itself might be the problem, I have tested opening it in a browser (to no avail). I also tried opening it in the plot window with the code below, but it just shows the same error (in lower resolution):
tiff_file <- tempfile()
image_write(annotated_graph, path = tiff_file, format = 'tiff')
r <- raster::brick(tiff_file)
raster::plotRGB(r)
I thought this might be a memory issue, but according to task manager there's several gigabytes of free RAM.
I'd be really happy to resolve the issue altogether, but finding a way to restart whatever component needs to be restarted without rebooting the entire system would already be splendid!
My specs: Win10 on AMD64, R 4.0.2, magick 2.4.0
I have issue with plotting lines over my existing plot in .Rmd in RStudio. I ran the code within the code chunk in .Rmd (⌘ + return) and the plot gives me a graph within the .Rmd (new feature of RStudio v1.0), however when I ran the second code lines, an error shows up.
plot(density(with$glucose),
ylim = c(0.00, 0.02),
xlab = "Glucose Level",
main = "Figure",
lwd = 2)
lines(density(without$glucose),
col = "red",
lwd = 2)
Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet
On the other hand, if I copy and paste the codes into the console, I could get the plot I want, in the plot viewer within RStudio.
In addition, when I ran some other codes within the .Rmd (⌘ + return), my plots in the plot viewer in RStudio disappear. This means I have to do copy-paste into the console instead of using the (⌘ + return) shortcut.
Does anyone have the same problem?
This is a known problem, but you can solve it very easy: Press Ctrl+Shift+Enter to run the complete chunk, then everything works fine and you don't have to copy-and-paste all thing to the console.
So do all your plots in one chunk and run this chunk. This will produce you the plot within the RMD file (as you mentioned: new feature of RStudio 1.0)
If you're not a fan of the inline output / notebook mode for R Markdown documents, you can also disable it within the Global Options dialog -- try disabling the option:
Show output inline for all R Markdown document