Plotting Tools

Statistical Computing, 36-350

Wednesday July 10, 2019

Last time: Data frames and apply

Part I

Plot basics: ggplot

Plotting in R

There’s 2 major styles of plotting in R. You’ve already seen examples of base R plots include

But… the R community has come to embrace a new approach to visualization from the ggplot2 package.

Extremely popular graphics library

Base graphics

Why ggplot2?

Basics: some terminology

Introduction to dataset

library(gapminder)
data(gapminder)

ggplot intro: scatter plot

library(ggplot2)
ggplot(gapminder, aes(y = lifeExp, x = gdpPercap)) + 
  geom_point()

ggplot intro: basic structure

ggplot(data = gapminder, aes(y = lifeExp, x = gdpPercap)) + 
  geom_point()
p <- ggplot(data = gapminder, aes(y = lifeExp, x = gdpPercap))
p + geom_point()

ggplot intro: change size

ggplot(gapminder, aes(y = lifeExp, x = gdpPercap)) + 
  geom_point(size = .1)

ggplot intro: add color

ggplot(gapminder, aes(y = lifeExp, x = gdpPercap, color = continent)) + 
  geom_point(size = .1)