A layered grammar of graphics – ggplot2

How do we translate all we have just read into R? Here comes the ggplot2 package to the rescue, developed by our beloved Hadley Whickam, who was one of the lucky students on the courses taught by the R creators Isaka and Gentleman. ggplot2 brings the power and logical simplicity of the grammar of graphics into the world of R, through the concept of layered plots. Every ggplot graphic is actually composed of at least the following programming components:

  • ggplot(data = data, aes()): Specifies the data and aesthetic layer
  • geom_whatever(): Introduces shapes representing the data within the data layer, following the specification given within the aes() layer

Those two are the minimum set of layers within the ggplot world. We can see that one more layer is implicitly set tighter with this one, which is the coordinates set, since Cartesian coordinates are automatically selected:

It is crucial to stress from now that every geom following the ggplot() call will inherit the aesthetics passed within that call if no different aesthetics are specified.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset