4

I have a very basic question. With the following sample code

x=seq(1,10, length=10)
y=rnorm(10)
plot(y~x, type="l", tck=-0.01,las=1, cex.axis=.90)   

I obtain the plot for which the distance between the axis ticks and the corresponding values looks big. I want to reduce that distance so that the values looks close to the ticks without increasing the size of ticks. How can I do this?

agamesh
  • 559
  • 1
  • 10
  • 26
Lucky
  • 61
  • 1
  • 1
  • 5
  • 2
    Have a look at [**this answer**](http://stackoverflow.com/questions/12302366/moving-axes-labels-in-r/12302557#12302557), especially "Update 1" and the use of `mpg` (see `?par`). Instead of using `par(mpg = `, you could add e.g. `mgp = c(3, 0.2, 0)` in your `plot` call (see the `...` argument in `?plot`). The `0.2` here means that the default margin line for axis labels is changed from 1 to 0.2, i.e. slightly closer to the ticks. – Henrik Feb 19 '15 at 13:49

1 Answers1

3

I don't know if this is a proper solution but I guess it does the trick: plot with option axt = "n" and then add the axis two times to get first the ticks and second the labels:

plot(y~x, type="l", xaxt ="n")
## add the ticks
axis(1, at = 1:10, label = rep("", 10), tck = -0.01)
## add the labels
axis(1, at = 1:10, line = -0.7, lwd = 0, cex.axis = 0.9)

you can change the vertical position by playing with line =. You can do the same operation for the yaxis, with axis(2,...

ClementWalter
  • 4,814
  • 1
  • 32
  • 54