Graphics in R
plot()
- Use
plot() to generate scatter plots and line graphs from numeric vectors.
- Use the arguments of
plot() to:
- Set the main (title) text.
- Label the horizontal and vertical axes.
- Set the horizontal and vertical limits of the plot.
- Set the color of points / lines.
- Set the type and size of points.
- Set the type and line width of lines.
- Use the
mfrow argument of par() to create a grid of plots.
- Save a PDF of a plot using
pdf() in combination with graphics.off()
points(), lines(), and abline()
- Add a scatter plot or line graph to an existing plot using
points() and lines(), respectively.
- Add horizontal and vertical lines to an existing plot using
abline.
- Add a line with a given intercept and slope to an existing plot using
abline.
- Construct a multi-layer graph using
plot() in combination with points(), lines(), and abline().
hist and density
- Create a histogram from a numeric vector using
hist().
- Use the arguments of
hist() to:
- Toggle between a frequency and density histogram.
- Set the placement of the bins for the histogram.
- Add a new histogram to an existing histogram.
- Compute and plot a kernel density estimate (more on this in a later lecture) using
density().
curve and rug
- Use
curve() to plot the graph of an expression on a desired interval.
- Use
curve() to add the plot of the graph of an expression to an existing plot.
- Add a rug plot to an existing plot using
rug().
Color Palettes
- You do not need to memorize the function names for the different color palettes.
- State the argument and return value for the functions for the different color palettes in R.
- Use
colorRampPalette() to generate a custom color palette along a gradient of colors.
- Explain what the
gg in ggformula stands for.
- Give the general grammar used by all plotting functions in
ggformula.
- Use
ggformula to generate:
- histograms
- density plots
- boxplots
- rug plots
- scatter plots
- Use the pipe operator
%>% to add elements to a ggformula plot.
- Use the
| operator to condition (“facet”) a graph on a categorical variable.
- Use
gf_lm and gf_smooth to add a least-squares line / nonparametric smoother to a scatter plot.
Packages in R
- Explain what an R package does.
- Install an R package from CRAN using
install.packages().
- Load an R package using
library().