Use of last_plot and xlim() in R



I was following a tutorial on ggplot2 package in R and used the following commands to plot data

qplot(cut, data = diamonds)
qplot(carat, data = diamonds)
qplot(carat, data = diamonds, binwidth = 1)
qplot(carat, data = diamonds, binwidth = 0.1)
qplot(carat, data = diamonds, binwidth = 0.01)
last_plot() + xlim(0, 3)

and I am getting an error saying->
Error: arguments imply differing number of rows: 313, 302

How to eliminate this error?
Edit: I used xlim(0,4) instead of xlim(0,3) and the error disappeared. What is the reason for this?



do ??xlim and you will get answer

Basically your first xlim gave an error because you were not giving enough space to the graph to be fit in

Convenience functions to set the limits of the x and y axis.