-1

How can I easily create a plot where the text is not overlapping?

Also How could I create a plot where I just label the first few points? Like the image below, I want to always label the bottom left hand part of the plot

xx<-c(2.25,5.5,5,9.5,7.75,14,24.5,20.75,28,25.5,11.25,17.75,11.75,20.5,23.5,5,10.5,5.5,11,12.5,15,26.75,15.25,24.25,27.75,10.25,22,11.25,18,22.5)
yy<-c(2.75,10.5,9.25,13.5,12,20,24.75,22,29,26.75,13,16.75,13.5,21,23,5.75,7.75,6.75,10.5,6.25,13.5,24.75,14,25.5,26.75,9.5,16.25,10.5,14.5,15)
nm_plot<-c("lastrem_0.5_NN","lastrem_0.25_NN","pt_0.5_NN","pt_0.25_NN","lastrem_NN","lastrem_0.5_area","lastrem_0.25_area","pt_0.5_area","pt_0.25_area","lastrem_area","lastrem_0.5_100","lastrem_100","lastrem_0.25_100","pt_0.5_100","pt_0.25_100","lastrem_0.5_100area","lastrem_100area","lastrem_0.25_100area","pt_0.5_100area","pt_0.25_100area","lastrem_0.5_200","lastrem_200","lastrem_0.25_200","pt_0.5_200","pt_0.25_200","lastrem_0.5_200area","lastrem_200area","lastrem_0.25_200area","pt_0.5_200area","pt_0.25_200area")

direct.label(xyplot(yy~xx,groups=nm_plot,col="Black",
                main=textGrob("7Q10",gp=gpar(fontsize=20,fontface="bold")),xlab="",ylab="",
                scales=list(tck=c(1,0),cex=1.5),xlim=c(0,35),ylim=c(0,35)),list("last.bumpup",cex=1.5))

How can I create the plot below in R enter image description here

user_123
  • 62
  • 12
  • Thats why I might just label the first few points, those are the ones that I care about the most – user_123 May 28 '16 at 17:13
  • I'd rather label them directly on the plot – user_123 May 28 '16 at 17:17
  • It appears you already have the requested result. Can you explain what is missing or wrong about the second graphic? – IRTFM May 28 '16 at 17:17
  • I created that in paint, I want to know how to create the second image in R using direct.label if possible – user_123 May 28 '16 at 17:18
  • Is it acceptable to first plot just the points you want labelled, and then add the remaining points without labels? – IRTFM May 28 '16 at 17:33
  • No because I need to automate this process, and the points I want labeled will change because I will be using new data – user_123 May 28 '16 at 17:39
  • Then you need to be more expansive about how the correct points are chosen. The problem is too vague right now. – IRTFM May 28 '16 at 17:40
  • Sorry about that, thank you for your help. The points that I want labeled will always be on the bottom left hand part of the plot – user_123 May 28 '16 at 17:42
  • First, you decide which points you want to label using some criteria, e.g., x < 15 and y < 15. Then use a smaller font to reduce overlapping. – JACKY88 May 28 '16 at 18:28

1 Answers1

0

Found a simple solution using ggplot2 and ggrepel.

xx<-c(2.25,5.5,5,9.5,7.75,14,24.5,20.75,28,25.5,11.25,17.75,11.75,20.5,23.5,5,10.5,5.5,11,12.5,15,26.75,15.25,24.25,27.75,10.25,22,11.25,18,22.5)

yy<-c(2.75,10.5,9.25,13.5,12,20,24.75,22,29,26.75,13,16.75,13.5,21,23,5.75,7.75,6.75,10.5,6.25,13.5,24.75,14,25.5,26.75,9.5,16.25,10.5,14.5,15)

nm_plot<-c("lastrem_0.5_NN","lastrem_0.25_NN","pt_0.5_NN","pt_0.25_NN","lastrem_NN","lastrem_0.5_area","lastrem_0.25_area","pt_0.5_area","pt_0.25_area","lastrem_area","lastrem_0.5_100","lastrem_100","lastrem_0.25_100","pt_0.5_100","pt_0.25_100","lastrem_0.5_100area","lastrem_100area","lastrem_0.25_100area","pt_0.5_100area","pt_0.25_100area","lastrem_0.5_200","lastrem_200","lastrem_0.25_200","pt_0.5_200","pt_0.25_200","lastrem_0.5_200area","lastrem_200area","lastrem_0.25_200area","pt_0.5_200area","pt_0.25_200area")


library(ggrepel)
library(ggplot2)

pp<-data.frame(xx,yy)
row.names(pp)<-nm_plot

plot1<-ggplot(pp) +
geom_point(aes(xx, yy), color = 'red') +
geom_text_repel(aes(xx, yy, label = rownames(pp))) +
theme_classic(base_size = 16)+theme_bw()+theme(panel.grid.major =   element_blank(), panel.grid.minor = element_blank())+
theme(axis.title.x = element_blank())+theme(axis.title.y = element_blank())+
scale_y_continuous(breaks=seq(0,30,5))+scale_x_continuous(breaks=seq(0,30,5))+
ggtitle("7Q10")+theme(plot.title = element_text(lineheight=.8, face="bold"))

enter image description here

user_123
  • 62
  • 12