Graphics Options#

For the examples below, we need to load some data.

pers <- read.csv('https://faculty.ung.edu/rsinn/data/personality.csv')
caff <- pers$Caff

Main Title#

The standard titles of various graphics in R can be awkward as demonstrated below.

plot(density(caff))
_images/93ce95114fc0a382768f0e34066849c91590ce80de446370a3d848110b02d01a.png
boxplot(caff)
_images/cfee7c9a70ad87d8fd6e78b8624145647ee6fc346484d7dff200be623aee1451.png

To change the main title for a graphical display, we use the option main = as shown below.

plot(density(caff), main = 'Density Plot: Daily Caffeine Consumption')
_images/84070f6bc402f84324b70685956c7e0005e6fab25c50fd33af5e842a01f2a7c1.png

Titles for X-axis and Y-axis#

The option xlab controls the \(x\)-axis label while ylab does the same for the \(y\)-axis label.

plot(density(caff),
     main = 'Density Plot: Daily Caffeine Consumption',
     xlab = 'Number of 8 oz Serving Per Day',
     ylab = 'Density')
_images/feec0dae1f5de91b5e5505ab464e02d03edc802e569ed9d8775d2b69ac067c2a.png

Line Width#

In certain graphics, we can emphasize things by increasing or decreasing line width with lwd parameter. The options available are shown in the graphic below.

Line Width

For example, let’s use a rather large width for the density plot with lwd = 4.

plot(density(caff), 
     lwd = 4,
     main = 'Density Plot: Daily Caffeine Consumption',
     xlab = 'Number of 8 oz Serving Per Day',
     ylab = 'Density')
_images/6c1d757bb8a5f5077cf1d8e04ff55459407e35438053afb6d2ad53280d98b294.png

Color#

The col = parameter allows to identify colors by name as in ‘red’ or by by hexidecimal code as in #FFC00. The simplest method is use color names, as shown below.

plot(density(caff), 
     lwd = 3,
     col = 'blue',
     main = 'Density Plot: Daily Caffeine Consumption',
     xlab = 'Number of 8 oz Serving Per Day',
     ylab = 'Density')
_images/39367ff1ceadd4c0bfdbeb2ff6cfabaaadda47a47b9730eb57566775bbf9bc52.png

Other Plot Types#

R is very consistent in allowing the standard graphical parameters to operate unchanged across a wide variety of different graphics. Some examples are shown below.

age <- pers$Age
boxplot(age, 
        main = "Ages")
_images/fb139880bbdab7f4103372a3a760f5038b10425f29d956de750fa9b74fc04bde.png
hist(age, breaks = 8,
    col = 'red',
    main = 'Histogram: Ages',
    xlab = 'Age in Years')
_images/535cb348df51963d142f492b9da99dfaafc4ffda30141de9dda32980850146b6.png