Graphs can provide excellent insight into data and help understand the relationships in the dataset. R is such a powerful tool for data analysis has many functions like
plot(), and many more, which can help make beautiful, useful graphs and many types.
Sometimes, one might need to make sure that the plot lies between certain values and not exceed these values. Two functions that can be used in such situations are the
xlim() functions. Both these functions are used to set the lower and upper limit on the y-axis and x-axis, respectively.
Let’s start with the
ylim() function. It specifies the upper and lower limit of the y-axis. It is a fundamental function and can be used inside the
plot(), and other plot functions as a parameter. In the example below, we will first plot a basic scatter plot of random distribution and then set the lower limit of the y-axis as 0 and the upper limit as 50 using
plot(sample(100), ylim = c(0,50))
Notice the change in the y-axis after setting the upper and lower limit.
Similarly we can use the
xlim() function for x-axis. For example:
plot(sample(100), ylim = c(0,50), xlim = c(0,50))