This post will cover up most of the basic ggplot2 package in R . On his website (http://had.co.nz/ggplot2/) package author Hadley Wickham describes ggplot2 as a plotting system for R, based on the grammar of graphics, which tries to take the good parts of base and lattice graphics and none of the bad parts. It takes care of many of the fiddly details that make plotting a hassle (like drawing legends) as well as providing a powerful model of graphics that makes it easy to produce complex multi-layered graphics. Grammar of Graphics is based on the concept of dividing a graph into 2 feartures namely : Data/Content and Aesthetics.This helps in a producing a graph rich with both content and handling beautiful aesthetics (i.e. the color of line,background etc.) very well even within a single line of code.
Unlike previous two plots ggplot doesn't come preinstalled (atleast not till this date).To install go to your R console and type
qplot is one of the two ways to produce graph using ggplot. The exact syntax for the same is ::
qplot(x, y, data=, color=, shape=, size=, alpha=, geom=, method=, formula=, facets=, xlim=, ylim= xlab=, ylab=, main=, sub=)
Here the variables share their usual meaning. Now we will use "mtcars" data to understand the functioning of this graph.
Unlike the other plots you can embed the aesthetics in the code itself like . To do this we use ggplot().
The syntax for ggplot() is the same . The only this is use of "+" to add features to the plot.
The great feature of ggplot is the use of + operator . To map the clear linear trend just type :
For further reading read this link
for documentation of ggplot2.