aWellingtonian
aWellingtonian

Reputation: 29

misplaced label on scatter plot data

I am quite new to R and was wondering if anyone could help with this problem: I am trying to graph a set of data. I use plot to plot the scatter data and use text to add labels to the values. However the last label is misplaced on the graph and I can't figure out why. Below is the code:

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

Upvotes: 0

Views: 49

Answers (1)

Bryan Hanson
Bryan Hanson

Reputation: 6213

Your probs request returns 11 values, but you only have 10 x values. Therefore R recycles your y values, and the 11th label is plotted at y = 1 when you add the text. How to fix this depends upon what you are trying to do. Perhaps in your probs sequence you want seq(0, 1, length.out = 10)?

Upvotes: 1

Related Questions