ggplot2 Plot a subset of data Using xlim / ylim


> library(ggplot2)
> ggplot(iris,aes(Sepal.Width)) + geom_density() + xlim(1,3.5)

Using xlim or ylim the plot is not cutted, ggplot subsets the data before calling the stat function (stat_density in this case). You can see it in the warning message.

Warning message:
Removed 19 rows containing non-finite values (stat_density).