Tutorial by Examples

> 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 cont...
ggplot(iris[iris$Species == "setosa",],aes(Sepal.Width)) + geom_density() Here, we are subsetting the dataframe before passing it to ggplot. It is a very useful tool derived from the data frame data structure. To make the code more readable, one can also use dplyr's filter: libr...

Page 1 of 1