Question

I am fairly new to R and am exploring the axis function. Here is a small piece of code

  x = seq(0,1,0.2)  
  y = seq(0,1,0.2)
  x1 = c(1,1)
  y1 = c(0,1)
  plot(x1,y1,,xlab="X-axis",ylab="Y-axis",axes=FALSE)
  axis(1,at=x,labels=x,pos =0)
  axis(2,at=y,labels=y)
  abline(0,1)

This is a simple xy graph. The labels on Y axis are exactly what I expect (0,0.2,0.4,0.6,0.8,1.0). However something weird is going on in the X axis. The labels here are (0.6,0.8,1). I have spent some time trying to figure it out but I seem to be stuck. Is this axis function a mere suggestion to the system which it may choose to ignore? What am I missing here? Thanks a lot for your help everybody? enter image description here

Was it helpful?

Solution

Instead of removing then remaking the axes just use this

plot(x1,y1,,xlab="X-axis",ylab="Y-axis",ylim=c(0,1),xlim=c(0,1))

By default R doesn't plot unnecessary white space, if you want extra white space then you force it with xlim and ylim arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top