散点图数据上的错误标签



我对R很陌生,想知道是否有人能帮助解决这个问题:我正试图绘制一组数据。我使用绘图来绘制散点数据,并使用文本为值添加标签。然而,最后一个标签放错了位置,我不明白为什么。以下是代码:

#specify the dataset
x<-c(1:10)
#find p: the percentile of each data in the dataset
y=quantile(x, probs=seq(0,1,0.1), na.rm=FALSE, type=5)
#print the values of p
y
#plot p against x
plot(y, tck=0.02, main="Percentile Graph of Dataset D", xlab="Data of the dataset", ylab="Percentile", xlim=c(0, 11), ylim=c(0, 11), pch=10, seq(1, 11,     1), col="blue", las=1, cex.lab=0.9, cex.axis=0.9, cex.main=0.9)
#change the x-axis scale
axis(1, seq(1, 11, 1), tck=0.02)
#draw disconnected line segments
abline(h = 1:11, v = 1:11, col = "#EDEDED")
#Add data labels to the graph
text(y, x, labels= (y), cex=0.6, pos=1, col="red")

probs请求返回11个值,但只有10个x值。因此,R回收您的y值,添加文本时,第11个标签绘制在y=1处。如何解决这个问题取决于你要做什么。也许在你的probs序列中,你想要seq(0, 1, length.out = 10)

最新更新