Building Blocks
Aesthetics 1
Aesthetics 2
Scales, Stats, and Coordinates
Themes and Faceting
100

What code would initialize a plot made from the mtcars dataset data set where hp (horsepower) is on the X axis and mpg (miles per gallon) is on the Y axis?

ggplot(mtcars, aes(x = hp, y = mpg))

100

What role do aesthetic mappings play in the creation of a ggplot?

Aesthetic mappings determine how values are assigned to the visual aspects of your plot.

100

What would the plot generated by the code below look like?

ggplot(iris, aes(y = Sepal.Width))

A blank plot with nothing but a Y axis.

100

What shorthand function (and the argument) could I use to add the caption "my caption" to my plot?

labs(caption = "my caption")

100

What code can I add to my plot to replicate the plot once for each value of e.g., a hair_color variable?

facet_wrap(facets = hair_color)

200

Which building block of ggplot - and the two subtypes - determines which type of plot will be drawn?

Layers

Two subtypes: geoms and stats

200

What is the difference between the color and fill aesthetics?

Color affects the colors of lines and points (for example, the colors of the borders around bars on a bar plot), while fill affects the color of white spaces (for example, the color of the area insides of bars on a bar plot).

200

Add the code to the code below that would make a dashed trend line:

geom_smooth()

geom_smooth(linetype = "dashed")

200

What determines the location of each aspect of a ggplot?

the coordinate system

200

What do the arguments of the theme function represent?

Each customizable aspect of your plot.

300

What does the facet_wrap function do?

Replicates the plot once for each unique value of another variable.

300

What is the difference between setting an aesthetic inside the aes() function vs setting it outside the aes() function but inside of a geom?

Inside of the aes() function, the aesthetic will be set to a variable, whereas outside of the function but inside a geom, it will be set to a user–specified value (e.g. a color).

300

What is the difference between a global versus local aesthetic?

Global aesthetics apply to the entire plot, whereas local aesthetics apply only to the specific geom they are used in.

300

Say that I wanted to plot the square root of a continuous variable located on the Y axis. What function could I use?

scale_y_continuous()

300

Which element function does the background of a plot go with?

element_rect()

400

What are the two ways that I can change the superficial appearance of my plot?

By adding one of the built-in themes or by manually cuctomizing specific aspects of the plot with the theme() function.

400

What would the following argument do to my bar plot:

aes(x = species, y = mass, color = gender)

It would make the color of points and/or lines in the plot depend on the gender variable.

400

What aesthetic would make the color of the inside of all of my violin plots pink? Note: must specify the location of the argument ;)

fill = "pink" (outside of the aes() function, inside of the geom, or geom_violin() in this case).

400

When using geom_bar() with a continuous variable on the Y axis, what is the argument that makes the top of each bar equal to the mean of that variable?

stat = "summary"

400

Name an aspect of a ggplot that corresponds to the  element_text() function used by theme().

Some possibilities...

- plot.title
- plot.caption
- axis.title.x/asxis.title.y
- axis.text.x/axis.text.y
- legend.text

500

Say I want to manually change the fill of the bars on my bar chart. Which function could I add to my ggplot to do that?

scale_fill_manual()

500

What is the difference between a plots aesthetics and its scales?

Aesthetics assign variables to different aspects of the plots, and scales do the work of actually drawing each aspect of the plot.

500

Say I wanted to make a scatter plot where the size of the points depends on the value of the pedal dark length variable. What would the argument and its setting be? Note: the location of the argument must be specified ;)

size = Pedal.Length (inside of the aes() function).

500

When using geom_histogram(), which only accepts an aesthetic mapping for the X axis (but not the Y axis), what role is the step function playing in creating this plot?

It is calculating the count variable that is displayed on the way access.

500

If I want to change the horizontal and vertical position of something on my plot along the coordinate system, which arguments would I use (e.g., inside of one of the element functions)?

hjust and vjust (which stand for horizontal justification and vertical justification, respectively).