86 Exercise 4

Use the faithfuld data set in R to plot waiting vs eruptions and add a layer of rectangles(to create a heat map) using the most high performing function(out of the three that we covered). Add density as the fill aesthetic and smooth out the graph.

ggplot(faithfuld, aes(waiting, eruptions)) +
 geom_raster(aes(fill = density), interpolate = TRUE) 

86.1 Common mistakes and errors

  • When dealing with violin plots you may get a warning such as “Warning: Removed 3 rows containing missing values (geom_segment).” This is due to the way ggplot2 deals with out of range axes and can be fixed using the ylim or xlim functions.
  • When working with ggplot, I occasionally find myself using the pipe operator(%>%) instead of using pipe instead of the plus (+). This might seem like a small mistake but I have often spent a lot of time staring at my code wondering why it isn’t working before realizing I was using the wrong operator.
  • If you are every stuck wondering why the properties you added for the graph are not working, ensure you have added them inside the plot layer and not the ggplot layer.

86.2 Next steps

86.4 Exercises

86.4.1 Question 1

  1. Which plot would you use to get the representation of the distribution of a numeric variable (pick all that apply)?
    1. Bar Plot
    2. Box Plot
    3. Violin Plot
    4. Density Plot

86.4.2 Question 2

  1. The Violin plot is a mixture of which plots (pick all that apply)?
    1. Scatter Plot
    2. Box Plot
    3. Histogram
    4. Density Plot

86.4.3 Question 3

  1. Which aesthetic determines which cases are connected together into a polygon (pick one)?
    1. Group
    2. Subgroup
    3. Alpha
    4. Fill

86.4.4 Question 4

  1. Which function is preferred when tiles are of the same size because it is the fastest (pick one)?
    1. geom_polygon()
    2. geom_rect()
    3. geom_raster()
    4. geom_tile()

86.4.5 Question 5

  1. Which plot will you use if you have three goals- you want to observe the distribution of numeric data, compare distributions between multiple groups and want to show the summary statistics (pick one)?
    1. Bar Plot
    2. Box Plot
    3. Violin Plot
    4. Scatter Plot

86.4.6 Question 6

  1. Which of these is not a parameter for geom_tile() (pick as many as apply)?
    1. x
    2. y
    3. xmin
    4. ymin

86.4.7 Question 7

  1. Which functions are useful when working with map data(pick all that apply)?
    1. geom_polygon()
    2. geom_violin()
    3. geom_raster()
    4. geom_polygon()

86.4.8 Question 8

  1. True or False: We need 4 data frames to construct a polygon using geom_polygon().
    1. True
    2. False

86.4.9 Question 9

  1. True or False: Polygons in R are just a variation of paths created by geom_path().
    1. True
    2. False

86.4.10 Question 10

  1. True or False: We can use interpolate=TRUE to smooth out the results after creating rectangular tiles.
    1. True
    2. False