Change Only One Axis Limit Using scale_x_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 x-axis using scale_x_continuous() function in the R programming language.

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_x_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.

Similar Reads

Using scale_x_continuous() or scale_y_continuous() function

scale_x_continuous()/scale_y_continuous() function: This function is for the default scales for continuous x or y aesthetics....

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....

Change Only One Axis Limit Using scale_x_continuous()

...