2016-12-13 64 views
1

使用wordcloud包,我需要將wordclouds調整爲矩形。 wordcloud本身的創建不成問題。我使用的是自定義函數:R-wordcloud調整爲矩形

createCorpus <- function (name, name2, output) { 

     # Here comes all the processing for generating a corpus 
     # irrelevant for this question 

     # Create wordcloud and save the image in png format 
     png(output, width=7.5, height=5, units="cm", res=140, bg = "white") 
     wordcloud(ordered.colors=TRUE, 
       words = topfeatures$keyName, 
       freq = topfeatures$value.x, 
       scale=c(1,.5), 
       min.freq=2, 
       max.words=10, 
       random.order=T, 
       rot.per=.0) 

    dev.off() 
} 

運行功能(f.i. :)

createCorpus(markenmonitoring$Content, "termsmm", "wcMM.png")

端生成與wordcloud一個PNG。然而,似乎所有這些wordclouds的形狀往往是圓形的。然而,在我的規範中,我需要創建矩形的wordclouds。 F.i:

How the end result should look like

通盤考慮,對於以前的圖像我已經手動調整「通知」 wordcloud。

我開始將rot.per參數更改爲.0,因此阻止垂直輸出單詞。但是,它似乎沒有幫助。只要我限制我輸出的高度(f.i:png(output, width=7.5, height=2.5, units="cm", res=140, bg = "white")),我收到以下錯誤:

Error in plot.new() : figure margins too large

問:我可以做R中wordclouds與圓形以外的形狀?

+0

您是否嘗試在'wordcloud'函數調用中設置'fixed.asp = F'? –

+0

看看[wordcloud2](https://cran.r-project.org/web/packages/wordcloud2/vignettes/wordcloud.html)。 – Henrik

回答

1

根據我在過去幾個小時的親身經歷,這是不可能的。
我已閱讀wordcloud package description,並且沒有任何參數可以讓wordcloud水平。

+1

似乎這是不可能的。沒有可能的解決方案,我一直在爲過去的2周而戰 – agustin