Skip to Content
R Graphics Cookbook
book

R Graphics Cookbook

by Winston Chang
December 2012
Beginner to intermediate
411 pages
8h 53m
English
O'Reilly Media, Inc.
Content preview from R Graphics Cookbook

Chapter 1. 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 book require the ggplot2 and gcookbook 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 book, 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 package repository. The primary repository for distributing R packages is called CRAN (the Comprehensive 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 package, choose the Austria site, which is the primary CRAN server.

Discussion

When you ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

R Graphics Cookbook, 2nd Edition

R Graphics Cookbook, 2nd Edition

Winston Chang
R Cookbook

R Cookbook

Paul Teetor
R Cookbook, 2nd Edition

R Cookbook, 2nd Edition

JD Long, Paul Teetor
R Statistics Cookbook

R Statistics Cookbook

Francisco Juretig

Publisher Resources

ISBN: 9781449363086Errata Page