1

我喜欢在背景 JPG 或 PNG 图像中使用水印来个性化我的图形。我用wordcloud2,RStudio,文字可以任意。也欢迎使用 wordcloud1 帮助。

如果 wordcloud2 不能像我注意到的那样用于 Letter、image、...,wordcloud1 可能是一个有趣的解决方案。

img <- readPNG(system.file("img", "Rlogo.png", package="png"), native=TRUE)

library(wordcloud2)
wordcloud2(data = demoFreq)

例如使用 R 标志作为水印我希望水印“R”出现在 wordcloud 的背景中。

4

1 回答 1

1

这是完成任务的一种方法。使用 时wordcloud2(),有一个参数可以指定背景颜色(即backgroundColor)。我认为backgroundColor = "transparent"这是要走的路。但似乎输出文件在背景中具有白色。(我可能做错了什么。如果是这样,请纠正我。)所以我最终使用 GIMP 来编辑 wordclouds。您甚至可以使用该软件将 wordcloud 覆盖在背景图像之上。但是,我选择使用magick包来使用 R。要使背景颜色透明,请参阅此问题。该问题包含您需要完成的所有步骤。

wordcloud 准备好后,您可以运行下面的代码。我希望这可以帮助你。

library(magick)

# Import images
words <- image_read("my_wordcloud.png")
logo <- image_read("R.svg")

# Stack layers
img <- c(logo, words)
img <- image_scale(img, "500x500")
image_info(img)

# combine the layers into a single image 
foo <- image_flatten(img)

# Save the image
image_write(foo, path = "so.png", format = "png")

在此处输入图像描述

于 2019-02-20T08:25:54.737 回答