2013-10-29 115 views
0

可以說我有一個列表名稱的Label1如下面打印列表爲PNG圖像格式

[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

我會說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

+0

謝謝!這太棒了! – Napmi

+0

很高興幫助。查看[wordclouds](http://stackoverflow.com/questions/18902485/colored-categories-in-r-wordclouds)也有一些樂趣。 (我在原始答案中放入了一個不同庫的鏈接。) – beroe

1

在gplots包中嘗試textplot