1 of 10

ggplot2 two

BIOS 611: Introduction to Data Science

Instructor Matt Biggs

2 of 10

Overview of today

  • Logistics:
    • First homework due by the end of next class
  • Review last class materials on ggplot
  • ggplot continued—plotting in R

BIOS 611

3 of 10

Review

  • Aesthetics:
    • ggplot(dataset, aes(x=col1, y=col2)) # set global figure properties
    • + geom_point(aes(size=col3)) # set layer-specific properties
  • Assigning colors manually:
    • Answer: scale_manual_fill(), scale_manual_color()
    • Example

BIOS 611

4 of 10

Objectives

  • Students will understand more ggplot syntax and be able to produce more advanced plots
  • Students will be familiar with R markdown (Rmd)

BIOS 611

5 of 10

More Syntax of ggplot

Lines and groups

Annotations

Axis limits

Expressions in labels

Themes

Legends

Hex colors

scripts/intro2ggplot2.R

BIOS 611

6 of 10

R markdown

Markdown is a simple, plain-text syntax for formatting text and document layouts.

For example (here’s a cheat sheet with many more commands):

*italics*, **bold**, # Header1, ## Header 2, * Bulleted list

![](image.png)

[text](hyperlink)

scripts/intro2rmd.Rmd

BIOS 611

7 of 10

GitHub markdown

There are lots of versions of Markdown. They’re all similar, with small variations in syntax.

For example here’s a GitHub markdown cheat sheet. This is what you use in a README.md in your Git repositories.

Unordered list:

* Item 1

* Item 2

* Item 2a

* Item 2b

BIOS 611

8 of 10

QUIZ

9 of 10

In-class practice

  1. Re-create the figure to the right using Rmd
  2. Name the Rmd document “diamond_bin.Rmd” and the knit PDF “diamond_bin.pdf”. Place in a directory called “class_examples” in your course Git repository.
  3. Push to GitHub.
  4. Hint: Notice that the theme is minimal, italics “G”, the bold “ideal”, the bulleted list, the figure title, the text annotation “G”

BIOS 611

10 of 10

Homework due next class

  1. Re-create the figure to the right using an R script and ggsave()
  2. Push the resulting script titled “HW1_your_github_id.R” and image “HW1_your_github_id.png” to Github classroom under a directory called “homework
  3. Hints:
    1. Load the “datasets” package and then load the CO2 data set.
    2. Pay attention to the expressions used in the axis labels and title to achieve the subscripts
    3. Use geom_smooth with se=FALSE
    4. Change the legend title
    5. Save with height=3, width=5
  4. Submit by midnight on the due date

BIOS 611