Change Only One Axis Limit Using scale_y_continuous
In this example, we will be plotting a ggplot2 plot of 10 data points for setting up the axis limit of only one axis which will be of y-axis using scale_y_continuous() function in the R programming language.
Initial plot with given data points look as without any changes:
R
library (ggplot2) data < - data.frame (x= c (4, 9, 5, 6, 10, 2, 3, 7, 8, 1), y= c (9, 4, 3, 1, 5, 2, 8, 10, 7, 6)) plot < - ggplot (data, aes (x, y)) + geom_bar (stat= "identity" ) plot |
Output:
Setting up the axis limit of only one axis which will be of y-axis using scale_y_continuous() function with the given data:
R
library (ggplot2) data < - data.frame (x= c (4, 9, 5, 6, 10, 2, 3, 7, 8, 1), y= c (9, 4, 3, 1, 5, 2, 8, 10, 7, 6)) plot < - ggplot (data, aes (x, y)) + geom_bar (stat= "identity" ) + scale_y_continuous (limits= c (0, 20)) plot |
Output:
Set ggplot2 Axis Limit Only on One Side in R
In this article, we are going to set the ggplot2 plot axis limit only on one side of the plot in the R programming language.