I'm not sure why there are differences between these two seemingly similar ways of plotting using ggplot2 and its geom_point options.
library(ggplot2)
data(mtcars)
If our goal is to plot two separate variables on the same plot, the slides suggest that we do the following:
ggplot(mtcars, aes(x=wt))+
geom_point(aes(y=disp),color="red") +
geom_point(aes(y=hp),color="blue")
In general, we can make plots in ggplot2 by assigning the plots and "adding" things to them.
p <- ggplot(mtcars, aes(x=wt))
p + geom_point(aes(y=disp),color="red") +
geom_point(aes(y=hp),color="blue")
If we do the addition in multiple steps, however, the plot will be overwritten as opposed to added on to.
p <- ggplot(mtcars, aes(x=wt))
p + geom_point(aes(y=disp),color="red") +
geom_point(aes(y=hp),color="blue")