-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
图3-9-3 单篇文章的词云图.R有问题 #6
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
commonality.cloud
library(tm)
library(wordcloud)
Paper1<-paste(scan("Paper1.txt", what = character(0),sep =""),collapse = " ") #读入 TXT 文档 1
Paper2<-paste(scan("Paper2.txt", what = character(0),sep =""),collapse = " ") #读入 TXT 文档 2
tmpText<- data.frame(c(Paper1,Paper2),row.names=c("Text1","Text2"))
df_title <- data.frame(doc_id=row.names(tmpText),text=tmpText$c.Paper1..Paper2.)
ds <- DataframeSource(df_title)
#创建一个数据框格式的数据源,首列是文档 id(doc_id),第二列是文档内容
corp = VCorpus(ds)
#加载文档集中的文本并生成语料库文件
corp = tm_map(corp,removePunctuation) #清除语料库内的标点符号
corp = tm_map(corp,PlainTextDocument) #转换为纯文本
corp = tm_map(corp,removeNumbers) #清除数字符号
corp = tm_map(corp,function(x){removeWords(x,stopwords())}) #过滤停止词库
term.matrix <- TermDocumentMatrix(corp)
#利用 TermDocumentMatrix()函数将处理后的语料库进行断字处理,生成词频权重矩阵
term.matrix <- as.matrix(term.matrix) #频率
colnames(term.matrix) <- c("Paper1","paper2")
#comparison.cloud(term.matrix,max.words=300,random.order=FALSE,colors=c("#00B2FF", "red"))
#图 3-9-4(a)
commonality.cloud(term.matrix,max.words=100,random.order=FALSE,color="#E7298A")
#图 3-9-4(b)
df<-data.frame(term.matrix)
#wordcloud(row.names(df) , df$Paper1 ,min.freq=10,col=brewer.pal(8,"Dark2"),rot.per=0.3 )
#图 3-9-3(a)
#wordcloud(row.names(df) , df$Paper2 , min.freq=10,col=brewer.pal(8,"Dark2"),rot.per=0.3 )
#图 3-9-3(b
错误是:> commonality.cloud(term.matrix,max.words=100,random.order=FALSE,color="#E7298A")
Error in is_overlap(x1, y1, sw1, sh1, boxes) :
程序包'Rcpp_precious_remove'不提供'Rcpp'这样的函数
The text was updated successfully, but these errors were encountered: