Graphics Reference
In-Depth Information
Chapter1.R Basics
This chapter covers the basics: installing and using packages and loading data.
If you want to get started quickly, most of the recipes in this topic require the ggplot2 and gcook-
book packages to be installed on your computer. To do this, run:
install.packages(c( "ggplot2" , "gcookbook" ))
Then, in each R session, before running the examples in this topic, you can load them with:
library(ggplot2)
library(gcookbook)
NOTE
Appendix A provides an introduction to the ggplot2 graphing package, for readers who are not already
familiar with its use.
Packages in R are collections of functions and/or data that are bundled up for easy distribution,
and installing a package will extend the functionality of R on your computer. If an R user creates
a package and thinks that it might be useful for others, that user can distribute it through a pack-
age repository. The primary repository for distributing R packages is called CRAN (the Compre-
hensive R Archive Network), but there are others, such as Bioconductor and Omegahat.
Installing a Package
Problem
You want to install a package from CRAN.
Solution
Use install.packages() and give it the name of the package you want to install. To install
ggplot2, run:
install.packages( "ggplot2" )
At this point you may be prompted to select a download mirror. You can either choose the one
nearest to you, or, if you want to make sure you have the most up-to-date version of your pack-
age, choose the Austria site, which is the primary CRAN server.
Search WWH ::




Custom Search