2 Individual geoms

2.1 Basic plot types

Q1: What geoms would you use to draw each of the following named plots?

  1. Scatterplot
  2. Line chart
  3. Histogram
  4. Bar chart
  5. Pie chart

A:

  1. Scatterplot: geom_point()

  2. Line chart: geom_line()

  3. Histogram: geom_histogram()

  4. Bar chart: geom_bar()

  5. Pie chart: geom_bar() + coord_polar()

Q2: What’s the difference between geom_path() and geom_polygon()? What’s the difference between geom_path() and geom_line()?

A: geom_polygon() is very similar to geom_path() except that the start and end points are connected and the inside is coloured by fill.

geom_path() connects the observations in the order in which they appear in the data, but geom_line() connects them in order of the variable on the x-axis.

Q3: What low-level geoms are used to draw geom_smooth()? What about geom_boxplot() and geom_violin()?

A:

  1. geom_smooth(): geom_path(), and geom_area().

  2. geom_boxplot(): geom_line(), geom_point(), and geom_rect().

  3. geom_violin(): geom_area(), and geom_path().