Change Spacing of Axis Tick Marks in Base R Plot (2 Examples)


In this article you’ll learn how to modify the space between axis ticks of a Base R plot in R programming.

The tutorial consists of the following topics:

Let’s get started:


Creation of Example Data

The following data will be used as basement for this R programming tutorial:

x <- 1:100        # Create example data
y <- 1:100

As you can see based on the previously shown R code, our example data is consisting of two numeric vectors ranging from 1 to 100.

As next step, we can draw our data with the plot function:

plot(x, y)        # Default axis ticks


r graph figure 1 change spacing axis tick marks base r plot


Figure 1 shows the output of the previous R code: A scatterplot with default axis ticks. In the following examples, I’ll show how to change the white space between those ticks manually…


Example 1: Change Spacing Between Axis Ticks Using xaxp & yaxp

This Example shows how to adjust axis tick intervals based on the xaxp and yaxp arguments of the plot function. For each of these two arguments, we need to specify a vector with the first and last tick mark positions as well as with the number of ticks:

plot(x, y,        # Change axis ticks with xaxp & yaxp
     xaxp = c(1, 100, 5),
     yaxp = c(1, 100, 9))


r graph figure 2 change spacing axis tick marks base r plot


As shown in Figure 2, we created a scatterplot with manually adjusted ticks on the x-axis and y-axis with the previously shown syntax.


Example 2: Change Spacing Between Axis Ticks Using axis() Function

The following R syntax shows how to change axis tick marks using the axis function. First, we have to create a plot without axis ticks. Second, we are adding ticks by applying the axis function:

plot(x, y,        # Change axis ticks with axis function
     xaxt = "n",
     yaxt = "n")
axis(side = 1, at = c(10, 50, 100))
axis(side = 2, at = c(25, 50, 75, 100))


r graph figure 3 change spacing axis tick marks base r plot


The output of the previous R syntax is shown in Figure 3: It shows the same xy-plot with axis tick marks at different positions.


Video, Further Resources & Summary

I have recently released a video on my YouTube channel, which explains the R programming syntax of the present post. Please find the video below.



Besides the video, you may want to read the other articles of my website:


In summary: In this article you learned how to adjust the interval between axis tick marks in the R programming language. If you have further questions, don’t hesitate to let me know in the comments below.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

4 Comments. Leave new

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.