I am creating a plot in R and I dont like the x axis values being plotted by R.
For example:
x <- seq(10,200,10)
y <- runif(x)
plot(x,y)
This plots a graph with the following values on the X axis:
50, 100, 150, 200
However, I want to plot the 20 values 10,20, 30 ... 200 stored in variable x, as the X axis values. I have scoured through countless blogs and the terse manual – after hours of searching, the closest I’ve come to finding anything useful is the following (summarized) instructions:
- call
plot()orpar(), specifying argumentxaxt='n' - call
axis()e.g.axis(side = 1, at = seq(0, 10, by = 0.1), labels = FALSE, tcl = -0.2)
I tried it and the resulting plot had no x axis values at all. Is it possible that someone out there knows how to do this? I can’t believe that no one has ever tried to do this before.
You’ll find the answer to your question in the help page for
?axis.Here is one of the help page examples, modified with your data:
Option 1: use
xaxpto define the axis labelsOption 2: Use
atandseq()to define the labels:Both these options yield the same graphic:
PS. Since you have a large number of labels, you’ll have to use additional arguments to get the text to fit in the plot. I use
lasto rotate the labels.