【问题标题】:display wordcloud with ggarrange and qplot使用 ggarrange 和 qplot 显示 wordcloud
【发布时间】:2021-03-16 15:12:57
【问题描述】:

我正在尝试从 R wordcloud 包中获取词云图,以使用 ggarrange 显示,但事实并非如此。 wordcloud 代码如下所示:

Essay_wc[[cor]] <- wordcloud(d_essay$word, d_essay$freq, colors=brewer.pal(6, "Dark2"), min.freq=10, max.words=800, scale=c(3,.4), random.order=FALSE, rot.per=0.35)

我在 ggarrange 中使用的其他图表如下所示

 
  emo_plot[[cor]] <- qplot(sentiment, xlab="After Essay emotions", data=td_emo, weight=count, geom="bar",fill=sentiment)+ggtitle(pdfNames[cor])+theme(axis.title.x = element_text(size = 9, lineheight = .9,family = "Times", face = "bold.italic", colour = "red")) + theme(plot.title = element_text(size = 9, lineheight = .9,family = "Times", face = "bold.italic", colour = "red"))
  
  
  
  sentiment_plot[[cor]] <- qplot(sentiment, xlab ="After Essay sentiments in binary terms", data=td_sentiment, weight=count, geom="bar",fill=sentiment)+ggtitle(pdfNames[cor])+theme(axis.title.x = element_text(size = 9, lineheight = .9,family = "Times", face = "bold.italic", colour = "red")) + theme(plot.title = element_text(size = 9, lineheight = .9,family = "Times", face = "bold.italic", colour = "red"))

ggarrange 代码如下所示:

graphsList=list()
for(i in 1:length(my_corpus)){  #length(my_corpus)
  graphsList=c(graphsList,emo_plotB[i])
  graphsList=c(graphsList,sentiment_plotB[i])
  graphsList=c(graphsList,emo_plot[i])
  graphsList=c(graphsList,sentiment_plot[i])
}

pdf("BeforeAndAfterIrreg.pdf",onefile=TRUE)
#do.call(ggarrange, c(graphsList, list(ncol = 2, nrow=3, rremove("x.text"), align="hv" ) ))
do.call(ggarrange, c(graphsList, list(ncol = 2, nrow=4, rremove("x.text") ) )) #align="hv"
dev.off()

有人对如何做到这一点有建议吗?我试过了,但它没有显示 wordcloud

graphsList=list()
for(i in 1:length(my_corpus)){  #length(my_corpus)
  graphsList=c(graphsList,emo_plotB[i])
  graphsList=c(graphsList,sentiment_plotB[i])
  graphsList=c(graphsList,emo_plot[i])
  graphsList=c(graphsList,sentiment_plot[i])
  graphsList=c(graphsList,Essay_wc[i])
}

【问题讨论】:

    标签: r ggplot2 word-cloud


    【解决方案1】:

    wordcloud 返回NULL,因此您不能将其存储在Essay_wc[[cor]] 中。尝试使用其他返回 wordcloud 图的方法。例如ggwordcloud 包。

    library(ggwordcloud)
    library(ggplot2)
    
    
    Essay_wc[[cor]] <- ggplot(d_essay, aes(label = word, size = freq)) +
                        geom_text_wordcloud()
    

    【讨论】:

    • 感谢您的解释和建议。有效!
    猜你喜欢
    • 2023-03-10
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多