Ranae Dietzel and Andee Kaplan
A layer added ggplot()
can be a geom…
… or a position adjustment to the scales
Plot | Geom | Stat |
---|---|---|
Scatterplot | point | identity |
Histogram | bar | bin count |
Smoother | line + ribbon | smoother function |
Binned Scatterplot | rectangle + color | 2d bin count |
More geoms described at http://docs.ggplot2.org/current/
Want to build a map using NOAA data
ggplot() +
geom_path(data = states, aes(x = long, y = lat, group = group)) +
geom_point(data = floats, aes(x = Longitude, y = Latitude, colour = callSign)) +
geom_point(aes(x, y), shape = "x", size = 5, data = rig) +
geom_text(aes(x, y), label = "BP Oil Rig", size = 5, data = rig, hjust = -0.1) +
xlim(c(-91, -80)) +
ylim(c(22, 32)) + coord_map()
animal <- read.csv("http://heike.github.io/rwrks/02-r-graphics/data/animal.csv")
ggplot
is pipeable!We can pass data as the first argument to ggplot()
… meaning we can pipe to it!
library(tidyverse)
data(baseball, package="plyr")
baseball %>%
filter(ab > 0) %>% #only players that have ever had an at bat
group_by(year) %>%
mutate(ba = h/ab,
mean_ba = mean(h/ab)) %>%
ggplot() +
geom_point(aes(year, ba), alpha = .1) +
geom_line(aes(year, mean_ba), colour = "blue")
During a ten week sensory experiment, 12 individuals were asked to assess taste of french fries on several scales (how potato-y, buttery, grassy, rancid, paint-y do the fries taste?)
French fries were fried in one of three different oils, and each week individuals had to assess six batches of french fries (all three oils, replicated twice)
Using the tidyverse
,
ff <- read.csv("http://heike.github.io/rwrks/03-r-format/data/frenchfries.csv")