2.13 Graphs as objects
A ggplot2 graph can be saved as a named R object (like a data frame), manipulated further, and then printed or saved to disk.
# prepare data
data(CPS85 , package = "mosaicData")
plotdata <- CPS85[CPS85$wage < 40,]
# create scatterplot and save it
myplot <- ggplot(data = plotdata,
aes(x = exper, y = wage)) +
geom_point()
# print the graph
myplot
# make the points larger and blue
# then print the graph
myplot <- myplot + geom_point(size = 3, color = "blue")
myplot