How to use xlim() and ylim() In R Language
This method clips the unused data, which means observations out of the set limit will not be sent to any layer and clipped off.
Syntax: plot+ xlim( xmin, xmax ) + ylim( ymin, ymax )
Example: Set Axis Limits in ggplot2 in R.
R
# Create sample data set.seed (5642) sample_data <- data.frame (x = rnorm (1000), y = rnorm (1000)) # Load ggplot2 library ( "ggplot2" ) # create plot with limits set ggplot (sample_data, aes (x = x, y = y)) + geom_point () + xlim (-5, 1)+ ylim (0, 5) |
Output:
How to set axis limits in ggplot2 in R?
In this article, we are going to see how to set the axis limit in ggplot2 in R Programming Language.
Contact Us