常见的解决方法有三种:
1. 使用wordcloud
#install.packages(c("wordcloud","tm"),repos="http://cran.r-project.org") library(wordcloud) library(tm) wordcloud("May our children and our children's children to a thousand generations, continue to enjoy the benefits conferred upon us by a united country, and have cause yet to rejoice under those glorious institutions bequeathed us by Washington and his compeers.",colors=brewer.pal(6,"Dark2"),random.order=FALSE) data(SOTU) SOTU <- tm_map(SOTU,function(x)removeWords(tolower(x),stopwords())) wordcloud(SOTU, colors=brewer.pal(6,"Dark2"),random.order=FALSE) states <- c('Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming') loc1 <- rnorm(50,c(0,0),matrix(c(1,.7,.7,1),ncol=2)) loc2 <- rnorm(50,c(0,0),matrix(c(1,.7,.7,1),ncol=2)) plot(loc1,loc2,type="n") text(loc1,loc2,states) #overlap textplot(loc[,1],loc[,2],states) #eliminate overlap
2. 使用direct label:
library(ggplot2) library(directlabels) x<-runif(10) y<-rnorm(10) z<-as.character(midwest$county[1:10]) q<-qplot(x,y)+geom_point(aes(colour=z)) direct.label(q, first.qp)
cited from:
http://drunks-and-lampposts.com/2012/02/22/labelling-a-ggplot-scatterplot/
http://blog.fellstat.com/?cat=11
http://stackoverflow.com/questions/21585128/how-to-avoid-overlapping-labels-with-identical-data-points-in-scatterplot-ggpl
本文介绍如何使用R语言的wordcloud和directlabel包进行文本数据的可视化处理,包括创建词云和改进散点图标签,避免标签重叠,适用于数据科学和文本分析领域的实践。
1297

被折叠的 条评论
为什么被折叠?



