Book contents
- Frontmatter
- Dedication
- Contents
- Preface
- Content-how the chapters fit together
- 1 A brief introduction to R
- 2 Styles of data analysis
- 3 Statistical models
- 4 A review of inference concepts
- 5 Regression with a single predictor
- 6 Multiple linear regression
- 7 Exploiting the linear model framework
- 8 Generalized linear models and survival analysis
- 9 Time series models
- 10 Multi-level models and repeated measures
- 11 Tree-based classification and regression
- 12 Multivariate data exploration and discrimination
- 13 Regression on principal component or discriminant scores
- 14 The R system – additional topics
- 15 Graphs in R
- Epilogue
- References
- Index of R symbols and functions
- Index of terms
- Index of authors
- Plate Section
15 - Graphs in R
Published online by Cambridge University Press: 05 October 2013
- Frontmatter
- Dedication
- Contents
- Preface
- Content-how the chapters fit together
- 1 A brief introduction to R
- 2 Styles of data analysis
- 3 Statistical models
- 4 A review of inference concepts
- 5 Regression with a single predictor
- 6 Multiple linear regression
- 7 Exploiting the linear model framework
- 8 Generalized linear models and survival analysis
- 9 Time series models
- 10 Multi-level models and repeated measures
- 11 Tree-based classification and regression
- 12 Multivariate data exploration and discrimination
- 13 Regression on principal component or discriminant scores
- 14 The R system – additional topics
- 15 Graphs in R
- Epilogue
- References
- Index of R symbols and functions
- Index of terms
- Index of authors
- Plate Section
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 RAn Example-Based Approach, pp. 472 - 492Publisher: Cambridge University PressPrint publication year: 2010