The grammar in R
Data, aesthetic mapping, geometry: every plot is those three plus extras.
library(ggplot2)
library(tibble)
runs <- tibble(
day = 1:6,
tpm = c(88, 92, 96, 99, 104, 101),
lang = rep(c("r", "python"), each = 3)
)
plot <- ggplot(runs, aes(x = day, y = tpm)) +
geom_point(size = 2) +
geom_line()
print(class(plot))
print(length(plot$layers))
ggsave(tempfile(fileext = ".png"), plot, width = 5, height = 3, dpi = 100)
How it works
aesmaps columns to visual properties.- A geom draws; layers add with
+. - The object is a value, so it can be stored and modified.
Keywords and builtins used here
aescclassgeom_linegeom_pointggplotggsavelengthlibraryprintreptempfiletibble
The run, in numbers
- Lines
- 16
- Characters to type
- 340
- Tokens
- 121
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 76 seconds.
Step 1 of 3 in The grammar, step 1 of 15 in ggplot2.