12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 18Looking At ggplot2 GraphicsIn This ChapterInstalling and loading the ggplot2 packageUnderstanding how to use build a plot using layersCreating charts with suitable geoms and statsAdding facets to your plotOne of the strengths of R is that it’s more than just a programming language— it also has thousands of packages written and contributed by independentdevelopers. One of these packages, ggplot2, is tremendously popular and offers anew way of creating insightful graphics using R.Much of the ggplot2 philosophy is based on the so-called “grammar ofgraphics,” a theoretically sound way of describing all the components that gointo a graphical plot. You don’t need to know anything about the grammar ofgraphics to use ggplot2 effectively, but now you know where its name comesfrom.In this chapter, you first install and load the ggplot2 package and then take afirst look at layers, the building blocks of the ggplot2 graphics. Next, you define thedata, geoms, and stats that make up a layer, and use these to create some plots.Finally you take full control over your graphics by adding facets and scales as wellas controlling other plot options, such as adding labels and titles.Installing and Loading ggplot2Because ggplot2 isn’t part of the standard distribution of R, you have todownload the package from CRAN and install it.In Chapter 3, you see that the Comprehensive R Archive Network (CRAN) is anetwork of servers around the world that contain the source code, documentation,and add-on packages for R. Its homepage is at http://cran.r-project.org.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!