我有一些可以正常工作的R代码,可以从术语文档矩阵生成标签云。

现在,我想从许多文档中创建一堆标签云,并在以后进行可视化检查。
要知道标签云图片属于哪个文档/语料库,我想在生成的图形中添加标题。我怎么做?

也许这很明显,但是我仍然是R图形的初学者。

我自己的语料库太大,无法在此处列出,但是可以使用此SO问题的代码(与来自SO用户Andrie的已接受答案的代码结合使用:
Spaces in wordcloud
我想在this之类的图片中添加自定义标题和更多自定义文本

最佳答案

wordcloud()函数填充整个图。这意味着在打印之前,需要在图形设备上为标题保留空间。

由于wordcloud使用基本字样,因此可以使用par(mfrow=...)layout()进行此操作。然后使用text()创建图标题。

我用layout()进行说明,改写?wordcloud中的示例:

library(tm)
library(wordcloud)

x <- "Many years ago the great British explorer George Mallory, who
was to die on Mount Everest, was asked why did he want to climb
it. He said, \"Because it is there.\"

Well, space is there, and we're going to climb it, and the
moon and the planets are there, and new hopes for knowledge
and peace are there. And, therefore, as we set sail we ask
God's blessing on the most hazardous and dangerous and greatest
adventure on which man has ever embarked."

layout(matrix(c(1, 2), nrow=2), heights=c(1, 4))
par(mar=rep(0, 4))
plot.new()
text(x=0.5, y=0.5, "Title of my first plot")
wordcloud(x, main="Title")


这将产生:

关于r - R:为wordcloud图形/png添加标题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15224913/

10-10 16:56