R tips

There were a couple of R questions in the last homework that I’ll answer.

How does one draw only two axes?

If you want to draw only two axes instead of the default four, first do your graph with the axes turned off:

library(MASS)
plot(log(mammals), axes = FALSE)

Then use the axis command twice to draw two axes with scales:

axis(1)
axis(2)

How do you get the scale-line rectangle and data rectangle to be the same?

You do it the same way as above. You plot, turning off the axes by specifying axes = FALSE. Then you use the axis function twice. For example, if you type

axis(1, at=seq(0, 10 2))

you are specifying that the x axis is drawn from 0 to 10 with tick marks at 0, 2, …, 10.

Leave a Reply

Your email address will not be published. Required fields are marked *