With thanks to this file by Jenny Bryan.
suppressMessages(library("ggplot2"))
suppressMessages(library("gapminder"))
gDat <- gapminder
p <- ggplot(gDat, aes(x = gdpPercap, y = lifeExp)) # just initializes
p + geom_point() # # scatterplot
# idem: p + layer(geom = "point")
#' log transformation ... quick and dirty
ggplot(gDat, aes(x = log10(gdpPercap), y = lifeExp)) + geom_point()
#' a better way to log transform
p + geom_point() + scale_x_log10()
#' let's make that stick
p <- p + scale_x_log10()
#' common workflow: gradually build up the plot you want
#' re-define the object 'p' as you develop "keeper" commands
#' convey continent by color: MAP continent variable to aesthetic color
p + geom_point(aes(color = continent))
ggplot(gDat, aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point() + scale_x_log10() # in full detail, up to now
#' address overplotting: SET alpha transparency and size to a value
p + geom_point(alpha = (1/3), size = 3)