I did some research and didn't find what I was looking for: I have a data set x = 10,100,1000 and y1, y2, y3 respectively, and I want to plot those points.

But what is happening is that in the x axis the values that are appearing are 10, 200, 400, 600, 800 and 1000. How can I set the scale so that it only appears the values I specified above? What I'm doing is:

y_values <- c(9, 9.6, 9.7, 9.8)
x_values <- c(10,100,1000)
plot(x_values, y_values)

Thank you.

  • 2
    $\begingroup$ Have you noticed that you have 4 y_values, but only 3 x_values? $\endgroup$ – gung - Reinstate Monica Mar 3 '14 at 23:35
  • 1
    $\begingroup$ The way to do this is explained here. $\endgroup$ – gung - Reinstate Monica Mar 3 '14 at 23:40
  • 2
    $\begingroup$ Since this question is only about how to do this in R, it is off-topic for CV (see our help center). For future reference, this Q could be on-topic on Stack Overflow, however, it will be off-topic there as well, since the answer already exists (as noted above). $\endgroup$ – gung - Reinstate Monica Mar 3 '14 at 23:42
  • 2
    $\begingroup$ This question appears to be off-topic because it is about how to use software. $\endgroup$ – gung - Reinstate Monica Mar 3 '14 at 23:42

You'll want to set axes=F, in the plot, the use the low-level axis function:

plot(x_values, y_values, axes=F)
axis(1, at=x_values, labels=as.character(x_values))
| cite | improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.