O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

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

Time for action – ggplot

ggplot, aes, and layer will be put in action to explore the power of the grammar of graphics.

  1. Load the library with library(ggplot2).
  2. Using the aes and ggplot functions, first create a ggplot object with galton_gg <- ggplot(galton,aes(child,parent)) and find the most recent creation in R by running galton_gg. You will get an error, and the graphics device will show a blank screen.
  3. Create a scatter plot by adding a layer to galton_gg with galton_gg <- galton_gg + layer(geom="point"), and then run galton_gg to check for changes. Yes, you will get a scatter plot of the height of child versus parent.
  4. The labels of the axes are not satisfactory and we need better ones. The strength of ggplot is that you can continue to add layers ...

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