♣9♣Visualisation Methods

This section demonstrates – in no particular order – some of the most useful plotting facilities in R.1

The most important function to plot anything is plot(). The OO implementation of R is function centric and the plot-function will recognize what object is fed to it and then dispatch to the relevant function. The effect is that you can provide a wide variety of objects to the function plot() and that R will “magically” present something that makes sense for that particular object.

We illustrate this with the two very basic and simple objects, a vector and a data frame (the plots appear respectively in Figure 9.1 on page 160 and Figure 9.2 on page 160):

If the standard plot for your object is not what you need, you can choose one of the many specific plots that we illustrate in the remainder of this chapter.

Graph depicts the plot-function will generate a scatter-plot for a vector.

Figure 9.1: The plot-function will generate a scatter-plot for a vector. Note also that the legend is automatically adapted. The xis is the index of the number in the vector and the y-axis is the value of the corresponding number in the vector.

Schematic illustration of the plot-function will generate a scatter-plot of each column in function of each other column for a data frame. The main diagonal of the matrix has the names of the columns.

Figure 9.2: The plot-function will generate a scatter-plot of each column in function ...

Get The Big R-Book 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.