r - How to label the first few points and create non-overlapping labels on a plot using direct.label -
how can create plot text not overlapping?
also how create plot label first few points? image below, want label bottom left hand part of 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))
found simple solution using ggplot2 , 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"))
Comments
Post a Comment