I would like to plot a scatterplot with y-axis is customized to step size of 0.2, within range of 0 – 2.6, and x-axis can be auto-defined. I tried the below, but it doesnt work. May I know how should I set the param correctly?
# Read data
pt.n <- read.table("p0_n300m20r1c1_regression.txt", header=T)
# auto-scale
# plot(pt.n$maee~pt.n$idx, main="P2PSim Seq#1,300n,20%,1r,Corrective", ylab="MAEE", xlab="Seq #")
# customize
ylabel <- c(0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6)
y_range <- range(0, ylabel)
plot(pt.n$maee~pt.n$idx, main="P2PSim Seq#3,300n,20%,1r,Corrective", ylab="MAEE", xlab="Seq #", ylim=y_range, axes=FALSE, ann=FALSE)
axis(1, at=0:6, lab=c(0,50,100,150,200,250,300))
axis(2, las=1, at=0.2*0:y_range[1])
box()
If something is not working check each bit of the thing that isn’t doing what you want to make sure you are supplying the correct data and haven’t made a booboo. If we run the bits of your code that are associated with the axis
You would immediately see the problem:
where you are basically telling R to draw a tick at 0. Even if you chose the correct element of
y_range(the maximum is in the second element) you still wouldn’t get the right answer:and that is because of the way the
:operator works. A call ofx:yis essentially a call toseq(from = x, to = y, by = 1)and because2.6+1is greater than2.6(thetoargument) R creates the sequence0, 1, 2.If you want to draw ticks and label at 0 – 2.6 incrementing by 0.2 then use:
where
ylabelnow contains:To illustrate:
which produces