tavareshugo / 2019-02-19-cambridge

Into to R - Data Carpentry course Cambridge 19-20 Feb 2019
https://tavareshugo.github.io/2019-02-19-cambridge
Other
0 stars 0 forks source link

Instructor notes #1

Open tavareshugo opened 5 years ago

tavareshugo commented 5 years ago

To make it easier for us, the exercises for the course have been compiled here.

Some notes on the things to cover:


note: extra material for ggplot2 section

So that students intuitively understand factors, introduce them in the plotting section.

The narrative goes something like this:

When doing this plot:

surveys_complete %>% 
  ggplot(aes(sex, hindfoot_length)) +
  geom_boxplot()

What if we want to change the order of the x-axis labels to be "M" first?

Then we need to learn about factors, which are a special way that R has to encode categorical variables.

Let's look at factors using a simple example first. Then go through the example of the course materials here, but only the very first section of it.

From there, jump back to the plotting problem and resolve it:

surveys_complete %>% 
  mutate(sex = factor(sex, levels = c("M", "F")))
  ggplot(aes(sex, hindfoot_length)) +
  geom_boxplot()

Exercise 3.4 applies this concept.

tavareshugo commented 5 years ago

Rough timings for sessions:

Day 1 AM:

Day 1 PM:

Day 2 AM:

Day 2 PM:

mvanrongen commented 5 years ago

Exercise 3.3

Part two, updating existing graph to add sex, does not include a solution.

yearly_diversity <- surveys_complete %>% 
  group_by(sex, year, plot_type) %>% 
  summarise(n_species = n_distinct(species_id)) %>% 
  ungroup()
yearly_diversity %>% 
  ggplot(aes(year, n_species)) +
  geom_line(aes(colour = plot_type)) +
  facet_grid(sex ~ .) +
  labs(colour = "Plot Type", x = "Year", y = "# species")