首页 > 其他 > 详细

text label overlap probelm

时间:2014-05-30 13:30:13      阅读:432      评论:0      收藏:0      [点我收藏+]

常见的解决方法有三种:

1. 使用wordcloud

bubuko.com,布布扣
#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 
bubuko.com,布布扣

2. 使用direct label:

bubuko.com,布布扣
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)
bubuko.com,布布扣

 

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

text label overlap probelm,布布扣,bubuko.com

text label overlap probelm

原文:http://www.cnblogs.com/shijun-xiao/p/3756214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!