我正在尝试使用R,syuzhet和wordcloud中的comparison.cloud函数来做一些推特情绪分析。输出中的单词与它们应该在的位置不一致。
我的矩阵(x)如下所示:
positive negative
marketing 11 10
learn 40 4
change 3 4
better 7 5
make 10 6
helping 6 5
代码如下:
x <- cbind(c(11,40,3,7,10,6),c(10,4,4,5,6,5))
rownames(x) <- c("marketing","learn","change","better","make","helping")
colnames(x) <- c("positive","negative")
comparison.cloud(x, colors = c("blue", "red"))
预期的结果是,“营销”、“学习”、“更好”、“制造”和“帮助”将是蓝色的“积极”方面,而“变化”将是红色“消极”的唯一方面。
实际发生的是"learn“是蓝色的,其余的都是红色的。
据我所知,comparison.cloud检查一个单词在“负”栏中的值是否大于0,如果有,它会自动将其绘制在“负”栏中,即使“正”是一个更高的数字。
有人知道怎么解决这个问题吗?
发布于 2019-08-24 01:43:58
你可以这样做:
x <- as.data.frame(cbind(c(11,40,3,7,10,6),c(10,4,4,5,6,5)))
x$types <- c("marketing","learn","change","better","make","helping")
colnames(x) <- c("positive","negative", "types")
x$all <- x$positive + x$negative
colorVec = ifelse(x$positive > 11, "blue", "red")
x <- x[,c("types", "all")]
library(wordcloud2)
wordcloud2(x, color = colorVec, fontWeight = "bold")
https://stackoverflow.com/questions/57630440
复制相似问题