Mon Oct 10, 2016

## 5NG

Today:

1. Scatterplot AKA bivariate plot
2. Linegraph
3. Boxplot
4. Histogram
5. Barplot AKA barchart AKA bargraph

## Exercise

Say we have the following piecharts represent the polling from a local election with five candidates (1-5) at three different time points A, B, an C:

• In the first race, is candidate 5 doing better than candidate 4?
• Who did better between time A and time B, candidate 2 or candidate 4?

## Barplots

• Barplots display information about a single categorical variable as the x aesthetic.
• The y-axis displays notions of relative frequency i.e. which values occur more than others.
• This is not an explicit variable in the data set, but rather is either
• Computed internally
• Computed manually by yourself

## Barplots

• geom_bar() is the trickiest of the 5NG in ggplot2, hence me presenting it last
• Correspondingly, we'll use it in limited capacity in this class and no need to open can of worms.
• If, however, you are feeling adventurous and want to open the can, feel free to ask me anyway!

## Barplots

Recall from Lec05 Slide 16, we displayed

## Chief Difficulty with Barplots

There are two different ways to input the data:

• Where the counts are not pre-computed (today)
• Where the counts are pre-computed

## Example

Counts are not pre-computed:

Row Number name
1 Albert
2 Albert
3 Albert
4 Virginia
5 Virginia

## Example

Counts are pre-computed in variable n. So n becomes a y aesthetic variable!

name n
Albert 3
Virginia 2