Lecture Synopsis

Think Before You Plot

alt text

Always plot on a piece of paper before attempt on a computer.

Know you data and its data structure; discrete, continues, etc.

Types of Graphics Functions

High-level

Functions such as plot, hist, boxplot, pairs that produce an entire plot or initialize a plot

Low-level

Functions that add to an existing plot created with a high-level plotting function. Examples are points, lines, text, axis, …

Trellis Functions

Functions such as xyplot, bwplot or histogram; mostly from the lattice package that can produce an entire multipanel display in a single call.

Basic R Graphic

Scatter Plot

Basic Scatter Plot

The following codes was adapted from Dr. Thomas Girke from UCRiverside Workshop

To plot a scatter-plot, we need 2 vector of values. Here we demonstarte how to do a scatter-plot using the first 2 column of y

alt text

set.seed(410)
y = matrix(runif(30), ncol = 3, dimnames = list(letters[1:10], LETTERS[1:3]))
print(y)
##           A          B         C
## a 0.6233786 0.45485054 0.1851294
## b 0.2576807 0.04615078 0.5469933
## c 0.5278801 0.62242588 0.3005991
## d 0.1119331 0.86551590 0.9414906
## e 0.3495442 0.33578687 0.2112313
## f 0.6440248 0.10736298 0.9615659
## g 0.7645591 0.84358448 0.4328838
## h 0.7119199 0.84002666 0.1502189
## i 0.7838755 0.90831252 0.6381334
## j 0.3957573 0.74661158 0.4525119
plot(y[,1], y[,2])

Exercise:
Plot column 1 vs. column 3 instead.

Scatter Plot with Labels

Let’s add a label and make the red color col="red" round dot pch=20

The look up tables were adaptor from Quick-R look up table

Once you have some familiarity on the terminology; check out the ENDMEMO resources for a quick reference.