muffa
muffa

Reputation: 11

R axis() problems with getting ticks

When using axis() with R, it doesn't produce correct ticks. Don't know what I'm doing wrong. My code is like the following, first producing a blank plot and then adding axis():

plot(1,1,xlab=NA,ylab=NA,type="n",xaxt="n",yaxt="n")
axis(1,at=c(1,2,3))

Either it produces just on tick in the middle of the axis or it isn't doing anything. It doesn't matter, what vector I use, it's always producing the same, no matter how many numbers I use or if I'm using a sequence, etc... Anyone with an idea what the problem could be?

Upvotes: 0

Views: 55

Answers (1)

Daniel
Daniel

Reputation: 2239

It does not show the ticks because your initial plot is bounded on the x axis from 0.5 to 1.5. This why the axis ticks for 2 and 3 are not shown. If you increase the range of the plotted x axis with xlim = c(0,4) for example, your ticks will be shown as well.

plot(1,1,xlab=NA,ylab=NA,type="n",xaxt="n",yaxt="n",xlim =  c(0,4))
axis(1,at=c(1,2,3))

Upvotes: 1

Related Questions