用 ggarrange 和 qplot 显示 wordcloud

display wordcloud with ggarrange and qplot

我正在尝试从 R wordcloud 包中获取词云图以使用 ggarrange 显示,但它们不是。词云代码如下所示:

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])
}

wordcloud returns NULL 所以你不能将它存储在 Essay_wc[[cor]] 中。尝试使用 return wordcloud plot 的其他方法。例如 ggwordcloud 包。

library(ggwordcloud)
library(ggplot2)


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