O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Graph using qplot

A simplistic version of ggplot is qplot and it uses the same ggplot2 package. qplot can also be chained with + to add additional layers in the plot. The generic form of qplot is as follows:

> qplot(x, y, data=, color=, shape=, size=, alpha=, geom=, method=, formula=, facets=, xlim=, ylim= xlab=, ylab=, main=, sub=)

For certain types of graphs such as histograms and bar charts, we need to supply only x (and can therefore omit y):

> # Regression of mpg by weight for each type of cylinders> qplot(weight, mpg, data=auto, geom=c("point", "smooth"), method="lm", formula=y~x, color=cylinders, main="Regression of MPG on Weight")

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required