Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R axis not displayed

I am afraid I have lost the plot, literally! Why does the axis command not put an x axis in the following plot? It must be something ridiculous, as I can't simplify much more.

yar <- c(.2,.1,.05,.03,.02)
plot(yar,xaxt='n')
axis(1, at=c(0.01,0.02,0.03,0.04,0.05))
like image 998
Helmut Avatar asked Sep 28 '22 05:09

Helmut


1 Answers

The reason your x axis is not appearing is that your placed it in a region of the plot where it is so small that it is not visible as output. You issued the following plot command:

plot(yar, xaxt='n')

which is really the same as doing

plot(c(1:5), yar, xaxt='n')

Since you never specified any x values, the default x value are just the counting numbers 1 through 5 corresponding to y values you did specify.

The solution to the problem is to place the x-axis where it will be visible. Hence you can try the following code:

xar <- 0.01*c(1:5)
yar <- c(.2,.1,.05,.03,.02)
plot(xar, yar, xaxt='n')
axis(1, at=xar)
like image 159
Tim Biegeleisen Avatar answered Nov 09 '22 23:11

Tim Biegeleisen