R:为wordcloud graphics / png添加标题 [英] R: add title to wordcloud graphics / png

查看:799
本文介绍了R:为wordcloud graphics / png添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

现在我想从许多文档创建一大堆标签云,并在以后直观地检查它们。
要知道标签云图片属于哪个文档/语料库,我会为所生成的图形添加标题。我怎么做?



也许这是显而易见的,但我仍然是一个初学R图形的人。



我自己的语料库是太大以至于无法在此处列出,但是可以使用以下SO问题的代码(与SO用户Andrie接受的答案相结合的代码):
wordcloud中的空格
我想为像

解决方案< > wordcloud()函数填充整个图表,这意味着在绘图之前您需要在图形设备上为标题保留空间。



wordcloud 利用基本图片,您可以使用 par(mfrow = ...) layout()。然后用 text()来创建图片标题。

我用 layout(),ada来说明在中举例

  library(tm)
图书馆(wordcloud)

x< - 许多年以前,英国探险家乔治马洛里(George Mallory)在珠穆朗玛峰上死去,他被问到为什么他想爬上
它。他说:因为它在那里。

好​​吧,空间在那里,我们要爬上去,而
月球和行星就在那里,对知识
和和平有新的希望。因此,当我们启航时,我们问
上帝的祝福,关于人类曾经踏上过的最危险,最危险和最伟大的
冒险。

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,我的第一个小区的标题)
wordcloud(x,main =Title)

这会产生:


I have some working R code that generates a tag cloud from a term-document matrix.

Now I want to create a whole bunch of tag clouds from many documents, and to inspect them visually at a later time. To know which document(s)/corpus the tag-cloud picture belongs to, I'd lke to add a title to the generated graphic. How do I do that?

Maybe this is obvious, but I'm still a beginner with R graphics.

My own corpus is too big to list it here, but the code from this SO question (combined with the code form the accepted answer from SO user Andrie can be used: Spaces in wordcloud I want to add a custom title and some more custom text to a picture like this

解决方案

The wordcloud() function fills the entire plot. That means you need to reserve space on your graphics device for the title before plotting.

Since wordcloud make use of base grapics, you can do this with either par(mfrow=...) or layout(). Then create the plot title with text().

I illustrate with layout(), adapting the example in ?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")

This generates:

这篇关于R:为wordcloud graphics / png添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆