Replace X-Axis Values in R (Example) | How to Change & Customize Ticks


In this R tutorial you’ll learn how to modify x-axis values manually.

The content of the post looks as follows:

Let’s get started.


Creating Example Plot

Let’s first create an exemplifying graphic in R:

plot(1:5)                       # Create plot in Base R


default axis r

Figure 1: Plot with Default X-Axis Values.


Figure 1 shows the output of the previous R code: A scatterplot with an x-axis ranging from 1 to 5.


Example: Changing X-Axis Values to Letters

Let’s assume that we want to modify our x-axis tick marks so that the currently shown numbers are replaced by upper case letters. Then, we first have to create a graph without any axis values:

plot(1:5,                       # Create plot without x-axis
     xaxt = "n",
     xlab = "My X-Axis")


without x axis plot r

Figure 2: Plot without X-Axis Values.


Figure 2 shows our plot without axis values.

Now, we can add custom axis values by using the axis function as shown below:

axis(1,                         # Define x-axis manually
     at = 1:5,
     labels = LETTERS[1:5])


custom axis r

Figure 3: Plot with Custom X-Axis Values.


Figure 3 shows our final result: A scatterplot with custom axis values.


Video & Further Resources

Do you need more explanations on the R codes of this article? Then I can recommend having a look at the following video instruction which I have published on my YouTube channel. I show the R programming syntax of the present tutorial in the video.


Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.

YouTube Content Consent Button Thumbnail

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.


Furthermore, you might have a look at the related articles that I have published on my website. I have released numerous tutorials already.


In summary: You have learned in this tutorial how to change the values on our axis scale in the R programming language.

In this tutorial, I have illustrated how to do this based on an exemplifying scatterplot. However, please note that it would also be possible to change the axis values of other types of graphs such as a histogram, boxplot, barchart, line plot, or a density plot by using the same kind of R code.

If you have further questions, please let me know in the comments section 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

  • Scottie Teichmer
    February 3, 2022 12:54 am

    How can I customize ticks to string values? E.g. “Control”, “Trial 1”, “Trial 2”.

    Thank you for any help.

    • Hey,

      You can add basically any text you want by using the label argument in the axis function. Have a look at the following example code:

      plot(1:3,                       # Create plot without x-axis
           xaxt = "n",
           xlab = "My X-Axis")
      axis(1,                         # Define x-axis manually
           at = 1:3,
           labels = c("Control",
                      "Trial 1",
                      "Trial 2"))


  • How can I customize range in the axis, for instance point A= 5-10, B=10-15 and so on

    • Hey Apsana,

      Are you looking for this?

      plot(1:3,                       # Create plot without x-axis
           xaxt = "n",
           xlab = "My X-Axis")
      axis(1,                         # Define x-axis manually
           at = 1:3,
           labels = c("5-10",



Leave a Reply

Your email address will not be published.

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