Examples of Graphical Data Analysis Using R

Introduction

Most of the figures below come from Visualizing Data, by William Cleveland. Others are from Lattice: Multivariate Data Visualization with R, by Deepanyan Sarkar. For most figures, I provide two versions of the code: ggplot2 on the left, and Lattice on the right.

To see the R code that produced a figure, click on it. To download a copy of the code, right-click and select "save link as". Move the downloaded file into the directory (i.e. folder) that you want to work in. Then launch R. Before trying to execute (say) singstrip.r, you must make sure that R knows how to find it. At the R prompt, type getwd(). R will print out its own idea of the current working directory. If this is the directory where you put singstrip.r, then you are ready to proceed. If not, tell R which directory is the right one by typing something like setwd("/the/name/of/my/directory"). When you have got the directory straightened out, type the following two lines:

par(ask=T)
source("singstrip.r", echo=T)

The first line tells R to stop after each graph, so that you'll have a chance to examine it. The second one tells R to execute the commands in file singstrip.r. The echo=T argument is necessary, because without it R will not send the graphical output to your screen.

Once you do all this, you will be able to step through all the graphs by hitting the return key. For each file, the final graph looks like the one displayed on this web site.

Links to topics