Skip to content

Day2: ggplot2 #3

@snystrom

Description

@snystrom

Today we covered most of the material from lesson 2 leaving out most of the examples of how to customize ggplots.

We did exercises 1 through 3 in some capacity. We talked about factors a bit following the planned lesson, but we wound up using an example from the ggplot2 documentation do demonstrate how factors vs continuous variables work.

This happened because it was causing students issues when coloring data because there's an example in the ggplot2 reference manual that coerces a continuous variable to a factor

ggplot(mtcars, aes(wt, mpg)) +
  geom_point(aes(color = factor(cyl))

I had students replicate the plot without the factor call to see that ggplot by default makes it a color gradient. This is because the data type is a numeric not a factor.

I then used the factor(c("one", "two", "two", "three")) example to illustrate how factors have levels and their default assignment is alphanumeric ordering.

I ended the class by showing them how to make facets and how to use the labs function to rename axis labels and legend titles and showed them ggtitle to give a title to the plot. Finally, I told them about the theme() function and how it can be used to customize a lot of things, but I didn't give examples and instead pointed them to the ggplot2 reference page.

I told them to try to work on the final exercise outside of class and we will pick up & review it at the beginning of next weeks lesson.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DebriefNotes taken immediately after a class session, what worked, what didn't, how the day went.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions