Adjust specific text fields in ggplot to avoid a match

Given a set of dummy data:

V1<-c(1,10,30,22,22,20)
V2<-c(4,17,4,33,33.2,15)
V3<-c(20,20,15,34,33,30)
V4<-c("A","A","A","B","B","B")
DF<-data.frame(V1,V2,V3,V4)

If I were to plot the bubble like this:

symbols(DF$V1,DF$V2,circles=V3,inches=0.35,fg="darkblue",bg="red")
text(DF$V1,DF$V2,V4,cex=0.5)

I get some coincidence with the text of the 4th and 5th labels. Using the code below, I can remove this overlap by adjusting certain points

text(DF$V1,DF$V2+c( 0, 0, 0, 1, -1,0 ),V4,cex=0.5)

Which works fine, but I would like to work in ggplot. If I do a simple ggplot

ggplot(DF,aes(x=V1,y=V2,size=V3,label=V4),legend=FALSE)+geom_point(color='darkblue',fill="red", shape=21)+theme_bw()+geom_text(size=5)

I get the same overlap, but I don’t know how to adjust individual points to avoid overlapping. I tried using "thigmophobe.labels", but this sets up all the points. I would just adjust the dots that overlap a bit to make them readable.

+4
3

position=position_jitter() width height. ,

 + geom_text(size=5, position=position_jitter(width=1, height=2) )
+3

, , , :

+ geom_text(size = 5, check_overlap = T)

, .

+3

Try the package directlabels. He may have what you need. (In particular, the function is direct.labelwrapped around code ggplot.)

+1
source

All Articles