Adding more plot aesthetics
In their most basic form scatter plots can only visualize datasets in two dimensions through the x
and y
aesthetics of the geom_point()
layer. However, most data sets have more than two variables and thus might require additional plotting dimensions. ggplot()
makes it very easy to map additional variables to different plotting aesthetics like size
, transparency alpha
and color
.
Let’s consider the gapminder_2007
dataset which contains the variables GDP per capita gdpPercap
and life expectancy lifeExp
for 142 countries in the year 2007:
ggplot(gapminder_2007) + geom_point(aes(x = gdpPercap, y = lifeExp))

Mapping the continent
variable through the point color
aesthetic and the population pop
(in millions) through the point size
we obtain a much richer plot including 4 different variables from the data set:
