R ggplot
ggplot2 library
- ggplot2 is a plotting system for R: based on the grammar of graphs, handles many of the details automatically > install.packages("ggplot2") > library("ggplot2")
plotting with ggplot
-the qplot() function can be used to create most common graph types, while hiding ggplot's full power - histogram of one attribute > qplot(data=iris, x=Sepal.Length, main = "Histogram of Sepal.Length") - scatterplot of two attributes qplot(data=iris, x=Sepal.Length, y=Sepal.Width, color= Species) - we can use boxplots for one dimensional data per class qplot(data=iris, y=Sepal.Length, x=Species, geom="boxplot") - Facets show the same plot with different sub-collections of data labeled by levels of a factor > qplot(data=iris, y=Sepal.Length, x=Sepal.Width, facets=~Species) - plots can be stored in objects, and we can add additional layers > P <- qplot(data=iris, y=Sepal.Length, x=Sepal.Width, facets=~Species) > P + stat_smooth(method="lm") - lm is an ordinary least squares trendline, stat_smooth() also shows confidence intervals as grey areas
Saving plots
> ggsave("FacetsWithTrend.jpg") - detects the desired format based on file extension: eps, pdf, tex, jpeg, png, svg, and more > help(ggsave) to learn about other options