码迷,mamicode.com
首页 > 其他好文 > 详细

text label overlap probelm

时间:2014-06-07 02:47:09      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

常见的解决方法有三种:

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

标签:c   style   class   blog   code   java   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!