在散点图数据上放错了标签

时间:2015-03-23 02:17:48

标签: r

我对R很新,并且想知道是否有人可以帮助解决这个问题: 我试图绘制一组数据。我使用plot绘制散点图数据并使用文本为值添加标签。但是最后一个标签放在图表上是错误的,我无法弄清楚原因。以下是代码:

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

1 个答案:

答案 0 :(得分:1)

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