Zoom into ggplot2 Plot without Removing Data in R Last Updated : 24 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to zoom into the ggplot2 plot without removing data using ggplot2 package in the R programming language. The approaches to the zoom into ggplot2 plot without removing data are as follows: Zoom in to ggplot2 plot without Removing data using ylim()/xlim() functionZoom in to ggplot2 plot without Removing data using coord_cartesian() functionMethod 1: Using ylim()/xlim() function ylim()/xlim() function: Convenience function to set the limits of the y axis/x-axis. Syntax: ylim(...) xlim(...) Parameters: ...: if numeric, will create a continuous scale, if factor or character, will create a discrete scale. Example: In this, example, we will be using xlim() function to get the zoom into view of the ggplot2 bar plot of the given data without removing any initial data in the R programming language. R # load the packages library("ggplot2") # create the dataframe with letters and numbers gfg < -data.frame( x=c('A', 'B', 'C', 'D', 'E', 'F'), y=c(4, 6, 2, 9, 7, 3)) # plot the given data # with A,B and C as titles to the bars plot < -ggplot(gfg, aes(x, y, fill=x)) + geom_bar(stat="identity") plot+xlim('A', 'B', 'C') Output: Method 2: Using coord_cartesian() function The Cartesian coordinate system is the most familiar, and common, type of coordinate system. Setting limits on the coordinate system will zoom the plot (like you're looking at it with a magnifying glass), and will not change the underlying data like setting limits on a scale will. Syntax: coord_cartesian( xlim = NULL, ylim = NULL,expand = TRUE, default = FALSE, clip = "on") Parameters: xlim, ylim: Limits for the x and y axes.expand: If TRUE, the default, adds a small expansion factor to the limits to ensure that data and axes don't overlap.default: Is this the default coordinate systemclip: Should drawing be clipped to the extent of the plot panel? Example: In this, example, we will be using the coord_cartesian() function with ylim() function to get the zoom into view of the ggplot2 bar plot of the given data without removing any initial data in the R programming language. R # load the package library("ggplot2") # create the dataframe with letters # and numbers gfg < -data.frame( x=c('A', 'B', 'C', 'D', 'E', 'F'), y=c(4, 6, 2, 9, 7, 3)) # plot the catrtesian bar plot < -ggplot(gfg, aes(x, y, fill=x)) + geom_bar(stat="identity") plot+coord_cartesian(ylim=c(5, 7)) Output: Comment More infoAdvertise with us Next Article Remove Axis Labels and Ticks in ggplot2 Plot in R G geetansh044 Follow Improve Article Tags : R Language R-ggplot Similar Reads Draw ggplot2 Legend without Plot in R A legend in the graph describes each part of the plot individually and is used to show statistical data in graphical form. In this article, we will see how to draw only the legend without a plot in ggplot2. First, let us see how to draw a graph with a legend so that the difference is apparent. For 3 min read Set Origin of ggplot2 Plot Axes to Zero in R In this article, we will be looking at the approach to set the origin of the ggplot2 plot axes to zero with the help of some functions of R programming language. In this approach to set the origin of the ggplot2 plot axes to zero, the user first needs to install and import the ggplot2 package in the 2 min read Remove NA Values from ggplot2 Plot in R In this article, we are going to see how to remove the NA values from the ggplot2 plot in the R programming language. Using complete.cases() function complete.cases() function: This function will be returning a logical vector indicating which cases are complete, i.e., have no missing values. Syntax: 2 min read Remove Axis Labels and Ticks in ggplot2 Plot in R In this article, we will discuss how to remove axis labels and ticks in ggplot2 in R Programming Language. The axes labels and ticks can be removed in ggplot using the theme() method. This method is basically used to modify the non-data components of the made plot. It gives the plot a good graphical 2 min read How to create a plot using ggplot2 with Multiple Lines in R ? In this article, we will discuss how to create a plot using ggplot2 with multiple lines in the R programming language. Method 1: Using geom_line() function In this approach to create a ggplot with multiple lines, the user need to first install and import the ggplot2 package in the R console and then 3 min read Add Text to ggplot2 Plot in R In this article, we are going to see how to add Text to the ggplot2 plot in R Programming Language. To do this annotate() is used. It is useful for adding small annotations (such as text labels) or if you have your data in vectors, and for some reason don't want to put them in a data frame. Syntax: 2 min read Like