LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data...

9
LAB 2: ggplot2 3 February 2017 R. Jordan Crouser SDS192: Introduction to Data Science

Transcript of LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data...

Page 1: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

LAB 2: ggplot23 February 2017R. Jordan CrouserSDS192: Introduction to Data Science

Page 2: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

Announcements

• Lab 1: Intro. To R and RStudio: - Due: today by 4:59pm- 49 / 90 responses as of 9:22am

• HW#1 (Reading Data Graphics) now open on Moodle- Due: Wednesday Feb. 8 by 11:55pm

• Cool conference coming up:

Page 3: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

Outline

• 10-minute crash course in ggplot2• Rest of class: lab• TODO (if you haven’t already):

> install.packages(‘ggplot2’)

Page 4: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

10-minute crash course

“(g)rammar of (g)raphics”

Page 5: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

What is the “Grammar of Graphics”?

Big idea: independently specify plot building blocks and combine them to create just about any kind of graphical display you want.Building blocks of a graph include:- data (obvi.)- geometric objects (the literal stuff we draw)- aesthetic mappings (how we draw that stuff)- statistical transformations (underlying model)- scales (range of values, colors, etc.)- faceting (small multiples)

Page 6: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

Geometric objects (geom)

• In ggplot2, the actual marks we put on a plot are called geometric objects or geoms

• Examples include:- points (geom_point, for scatter plots, dot plots, etc.)- lines (geom_line, for time series, trend lines, etc.)- boxplot (geom_boxplot, for, well, boxplots!)- … and many more!

Page 7: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

Aesthetic mapping (aes)

• In ggplot2, an aesthetic means “something you can see”• Aesthetic mappings are set with the aes() function• Each type of geom accepts only a subset of all aesthetics.

• Examples include:- position (i.e., on the x and y axes)- color (“outside” color)- fill (“inside” color)- shape (of points)- line type- size- … and many more!

Page 8: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

All you really need to know…

geoms + aes()

Page 9: LAB 2: ggplot2 - Clark Science Centerjcrouser/SDS192/04-ggplot2.pdf · SDS192: Introduction to Data Science. Announcements • Lab 1: Intro. To R and RStudio: -Due: today by 4:59pm-49

Lab 2: ggplot2