将列表打印到png图像表单

时间:2013-10-29 14:51:25

标签: r

假设我有一个名单Label1,如下面的

[1] "adelaide"  "allah"     "ampamp"    "anak"      "anwar"     "audit"     "australia" "bajet"    
[9] "baru"      "bersama"   "blog"      "dato"      "doakan"    "dsai"      "eid"       "festival" 

我想把它全部打印成图像(png)。任何的想法?如果可能,还包括顶部的标题。我尝试使用

png(file.choose(), w=700, h=1000)
  par(mar=c(5,10,2,2))
  print(Label1)
dev.close()

然而,我认为这只适用于情节。

2 个答案:

答案 0 :(得分:2)

我会说textplot甚至word cloud可能更好,但这里有一种简单的方法可以让你有所控制......

Label1 = c("adelaide","allah","ampamp","anak","anwar","audit","australia","bajet","baru","bersama","blog","dato","doakan","dsai","eid","festival" )

# set up the empty frame
plot(c(0,100),c(0,100),xaxt='n',yaxt='n',type='n',xlab="",ylab="",
 main = "Image Title")

# set up the positions:
x = rep(seq(20,80,20),4)
y = c(20,20,20,20,40,40,40,40,60,60,60,60,80,80,80,80)

# plot the words using text()
text(x,y,Label1,col=rainbow(12))

输出:

enter image description here

单词云选项的一个示例:

library(wordcloud)
require(RColorBrewer)
wordcloud(Label1, colors=(rep(brewer.pal(8,"Spectral"),2)), ordered.colors=TRUE)

输出:

enter image description here

答案 1 :(得分:1)

在gplots包中尝试textplot