appendix C Graphics in base R
This appendix provides an alternative solution to the problem of visualizing data. There are many reasons why ggplot2
can be seen as a superior method of visualizing data, not least of which is the sophisticated application of the “grammar of graphics” philosophy. That’s not to say that what you’re about to see is useless, but as you learn more about ggplot2
, you’ll have fewer and fewer reasons to ever use these functions.
The simplest way to generate a base
plot is to call plot()
with vectors of x
and y
data, as in figure C.1:
plot(x = mtcars$disp, y = mtcars$mpg)
You’ll notice a few major differences in how this is written and what is produced. First, since you’re passing vectors (not bare names of columns), ...
Get Beyond Spreadsheets with R now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.