added the library("ggplot2")

So that it gives a meaningful error if you don't import it first