How to use xlim() and ylim() functions with ggplot2 In R Language
In this approach to change the axis intervals of the given plot, the user needs to install and import the ggplot2 package in the working console of the R programming language, here the ggplot2 package is responsible for creating the plots, then the user needs to call the xlim() and the ylim() function with the required parameters as per the user to change the axis intervals as required by the user, these functions will be called with the plot created with ggplot2 and this will be leading to the change in the plot axis intervals as defined by the users.
Example: Initial plot
R
gfg<- c (8,9,6,5,8,5,1,7,3,5) barplot (gfg) |
Output:
Example: Change axis intervals
R
library (ggplot2) gfg<- data.frame (x= c (8,9,6,5,8,5,1,7,3,5), y= c (9,6,5,4,2,5,6,7,4,1)) ggplot (data=gfg, aes (x=x, y=y)) + geom_point ()+ xlim (0,15)+ ylim (0,20) |
Output:
How to Change Axis Intervals in R Plots?
In this article, we will be looking at the different approaches to change axis intervals in the R programming language.