本文介绍了具有特定形状的 Wordcloud的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设,我有一个数据框,其中包含一些单词及其频率.我想在 R 中创建一个 wordcloud,其中包含徽标形状的文字,例如,twitter 徽标就像这样:

对于 wordcloud,有一个名为 wordcloud2 的包,运行演示只会给出单词的方形图像.我将如何添加我选择的特定图像作为 wordcloud 的形状?

wordcloud2(demoFreq) 只输出一个正方形.

解决方案

您可以使用 wordcloud2 包.它允许您使用任何图像作为蒙版.只需放入工作目录并使用 figpath 链接到它.下面是我用来制作 wordcloud 的代码.下面是wordcloud.

Suppose, I have a dataframe which contains some words with their frequencies. I want to create a wordcloud in R with the words inside the shape of a logo, for example, the twitter logo just like this:

For the wordcloud, there is a package named wordcloud2 and running the demo only gives a square image of the words. How would I add a specific image of my choice to be the shape of the wordcloud?

wordcloud2(demoFreq) only ouputs a square.

解决方案

You can use wordcloud2 package for that. It allows you to use any image as the mask. Just put in the working directory and link to it using figpath. Below is the code I used to make the wordcloud. Below that is the wordcloud. Here is the image I used as the mask.

library(wordcloud2)
wordcloud2(demoFreq, figPath = "twitter.jpg")

这篇关于具有特定形状的 Wordcloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:11