## 4.3 Grammar components & ggplot2 (2)

• See some of the components in Figure 4.1 below (Data: View(mtcars) and ?mtcars).
• Q: How could we read the code?
• Q: How would we execute that code to understand it?23
• Q: How can we best remember what a function/package/argument does?24
• Q: How do you write down code to make it readable? (line breaks, spaces etc.)
ggplot(mtcars, aes(x = mpg, y = drat)) +
geom_point(aes(color = factor(gear))) + # Point layer
stat_smooth(method = "lm") + # Statistical transformation layer
theme_light() + # Theme
xlab("Miles/(US) gallon") + # Lab
ylab("Rear axle ratio") + # Lab
guides(color = guide_legend(title = "Number of forward gears")) # Legend

1. Execute it line by line (or from inside to outside)! Same is true for dplyr code!

2. Either by its name directly.. often by knowing what an abbreviation stands for.