Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-dfsvx Total loading time: 0 Render date: 2024-04-29T01:12:12.936Z Has data issue: false hasContentIssue false

15 - Graphs in R

Published online by Cambridge University Press:  05 October 2013

John Maindonald
Affiliation:
Australian National University, Canberra
W. John Braun
Affiliation:
University of Western Ontario
Get access

Summary

This chapter starts with comments on the graphical devices that are available in R, on font families and fonts, on plotting symbols, and on R's color choices. It discusses the abilities in the lattice package in modest detail, with a more cursory discussion of the ggplot2 package.

Hardcopy graphics devices

The following writes the graph to the pdf file fossilfuel.pdf:

pdf(file=“fossilfuel.pdf”, width=6.5, height=6.5, pointsize=18)

# For pdf() and postscript(), heights and widths are in inches plot(carbon ˜ year, data=fossilfuel, pch=16) dev.off()

Other functions that open hardcopy graphics devices include png(), jpeg(), bmp(), and tiff(). Unless the default units=“px” is changed, height and width are in pixels. Use dev.off() to close the device, thus making the file available for display, or for printing, or for incorporation into a document. For a complete list of devices, and further details of specific devices, see help(Devices).

Subsection 1.5.4 described commands used to open graphics windows on commonly used implementations of R. Use dev.copy() to copy a graph from the display that is currently active to a hardcopy graphics device. For example:

plot(carbon ˜ year, data=fossilfuel, pch=16) # Display graph ## Now open pdf device and copy graph to it

dev.copy(pdf, file=“fossilcopy.pdf”)

Type
Chapter
Information
Data Analysis and Graphics Using R
An Example-Based Approach
, pp. 472 - 492
Publisher: Cambridge University Press
Print publication year: 2010

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Graphs in R
  • John Maindonald, Australian National University, Canberra, W. John Braun, University of Western Ontario
  • Book: Data Analysis and Graphics Using R
  • Online publication: 05 October 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139194648.018
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Graphs in R
  • John Maindonald, Australian National University, Canberra, W. John Braun, University of Western Ontario
  • Book: Data Analysis and Graphics Using R
  • Online publication: 05 October 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139194648.018
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Graphs in R
  • John Maindonald, Australian National University, Canberra, W. John Braun, University of Western Ontario
  • Book: Data Analysis and Graphics Using R
  • Online publication: 05 October 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139194648.018
Available formats
×