Open In App

Change Spacing of Axis Tick Marks in Base R Plot

Last Updated : 28 Apr, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to see how to modify the space between axis tick marks of a Base R plot in R programming.

It can be done in the following ways:

  1. Using xaxp & yaxp method.
  2. Using axis() Function.

Method 1: Using  xaxp & yaxp method

The first tick mark, last tick, and a number of tick mark parameters are given represented by a,b,c shown in the below syntax. These parameters are put into used to change in spacing between axis ticks in the base plot.

Syntax: plot(x, y, xaxp = c(a,b,c), yaxp = c(a,b,c))

Parameters :

  • a= first tick mark
  • b= last  tick mark
  • c= Number of tick marks

Example:

R




# Create example data
y <- 1:80
x <- 1:80   
  
# Change axis ticks with xaxp & yaxp
plot(x, y,        
     xaxp = c(1, 80, 4),
     yaxp = c(1, 80, 10)) 


Output:

Method 2: Using axis function.

In this method, first, there is a need to create a plot without axis ticks. Then, add ticks by applying the axis() function. Different ticks are added in the way as represented by a, b, c parameters in syntax. So, this is one such method to change the spacing between axis ticks in Base R Plot.

Syntax:

plot(x, y, xaxt = “n”,yaxt = “n”)

axis(side = 1, at = c(a, b, c….))

axis(side = 2, at = c(a, b, c…..))

Parameters:

a, b, c = values of axis ticks

Example:

R




# Create example data
y <- 1:120
x <- 1:120 
  
# Change axis ticks with axis function
plot(x, y,        
     xaxt = "n",
     yaxt = "n")
axis(side = 1, at = c(10, 40, 80))
axis(side = 2, at = c(15, 50, 75, 100))


Output:



Similar Reads

How to label plot tick marks using ggvis in R
In this article, we will be looking at the approach to label tick marks using ggvis in the R programming language. The data frame is then subjected to the ggvis operations using the pipe operator. The ggvis method is used to start ggvis graphical window. The ggvis method has the following syntax : ggvis( data , mp1, mp2.,) Arguments : data - The da
3 min read
Change Spacing Between Horizontal Legend Items of ggplot2 Plot in R
In this article, we are going to see how to change the space between horizontal legend items using the ggplot2 bar plot in R programming language. Here we are using a bar graph the same can be done to any other plot. For creating a simple bar plot we will use the function geom_bar( ). Syntax: geom_bar(stat, fill, color, width) Parameters : stat : S
2 min read
Remove Axis Values of Plot in Base R
In this article, we will be looking at the approach to remove axis values of the plot using the base functions of the R programming language. In this approach to remove the axis values of the plot, the user just need to use the base function plot() of the R programming language, and further in this function the user needs to use the axt argument of
2 min read
Move Axis Label Closer to Plot in Base R
In this article, we will discuss how to move the axis label closer to the plot in R Programming Language. Before changing the distance, let us see how the initial plot will look like. Example: C/C++ Code x &lt;- seq(-pi,pi,0.1) plot(x, sin(x), main=&quot;The Sine Function&quot;, ylab=&quot;sin(x)&quot;, type=&quot;l&quot;, col=&quot;blue&quot;) Out
2 min read
Rotate Axis Labels of Base R Plot
In this article, we are going to rotate the axis labels of the plot in the R programming language. To do this the user just needs to call the base function plot and use the las argument of this function with the specific values into it and this will be leading to the rotation of the labels of the plot as per the las argument value passed in the R p
2 min read
Adding axis to a Plot in R programming - axis () Function
axis() function in R Language is to add axis to a plot. It takes side of the plot where axis is to be drawn as argument. Syntax: axis(side, at=NULL, labels=TRUE) Parameters: side: It defines the side of the plot the axis is to be drawn on possible values such as below, left, above, and right. at: Point to draw tick marks labels: Specifies texts for
2 min read
Rotating and spacing axis labels in ggplot2 in R
In this article, we will discuss how to Rotate and space axis labels in the ggplot2 in the R Programming Language. Spacing the axis labels: We can increase or decrease the space between the axis label and axis using the theme function. The axis.txt.x / axis.text.y parameter of theme() function is used to adjust the spacing using hjust and vjust arg
3 min read
Set Aspect Ratio of Scatter Plot and Bar Plot in R Programming - Using asp in plot() Function
asp is a parameter of the plot() function in R Language is used to set aspect ratio of plots (Scatterplot and Barplot). Aspect ratio is defined as proportional relationship between width and height of the plot axes. Syntax: plot(x, y, asp ) Parameters: x, y: Coordinates of x and y axis asp: Aspect ratio Example 1: # Set seed for reproducibility set
1 min read
Plot Paired dot plot and box plot on same graph in R
R Programming Language is used for statistical computing and graphics. R was first developed at the University of Auckland by two professors Ross Ihanka and Robert Gentleman Dot Plot The dot plot is a graphical representation of how one attribute varies with respect to another attribute. On the x-axis, we usually plot the attribute with respect to
7 min read
Change Legend Size in Base R Plot
In this article, we will be looking at the approach to change the size of the legend in the plot in the R programming language. To change the legend size of the plot, the user needs to use the cex argument of the legend function and specify its value with the user requirement, the values of cex greater than 1 will increase the legend size in the pl
2 min read
Article Tags :