如何标记前几个点并使用 direct.label 在图上创建非重叠标签

How to label the first few points and create non-overlapping labels on a plot using direct.label

如何轻松创建文本不重叠的图?

另外,我如何创建一个只标记前几个点的图?如下图所示,我想始终标记绘图的左下角部分

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))

如何在 R 中创建下面的图

使用 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"))