Graphics in R

plot()

  1. Use plot() to generate scatter plots and line graphs from numeric vectors.
  2. Use the arguments of plot() to:
  3. Use the mfrow argument of par() to create a grid of plots.
  4. Save a PDF of a plot using pdf() in combination with graphics.off()

points(), lines(), and abline()

  1. Add a scatter plot or line graph to an existing plot using points() and lines(), respectively.
  2. Add horizontal and vertical lines to an existing plot using abline.
  3. Add a line with a given intercept and slope to an existing plot using abline.
  4. Construct a multi-layer graph using plot() in combination with points(), lines(), and abline().

hist and density

  1. Create a histogram from a numeric vector using hist().
  2. Use the arguments of hist() to:
  3. Compute and plot a kernel density estimate (more on this in a later lecture) using density().

curve and rug

  1. Use curve() to plot the graph of an expression on a desired interval.
  2. Use curve() to add the plot of the graph of an expression to an existing plot.
  3. Add a rug plot to an existing plot using rug().

Color Palettes

  1. You do not need to memorize the function names for the different color palettes.
  2. State the argument and return value for the functions for the different color palettes in R.
  3. Use colorRampPalette() to generate a custom color palette along a gradient of colors.

ggformula

  1. Explain what the gg in ggformula stands for.
  2. Give the general grammar used by all plotting functions in ggformula.
  3. Use ggformula to generate:
  4. Use the pipe operator %>% to add elements to a ggformula plot.
  5. Use the | operator to condition (“facet”) a graph on a categorical variable.
  6. Use gf_lm and gf_smooth to add a least-squares line / nonparametric smoother to a scatter plot.

Packages in R

  1. Explain what an R package does.
  2. Install an R package from CRAN using install.packages().
  3. Load an R package using library().