In [1]:
from ggplot import *
%matplotlib inline

Aesthetics

Aesthetics describe how your data will relate to your plots. Some common aesthetics are: x, y, and color. Aesthetics are specific to the type of plot (or layer) you're adding to your visual. For example, a scatterplot (geom_point) and a line (geom_line) will share x and y, but only a line chart has a linetype aesthetic.

Aesthetics are specific to geoms, but here is a list of all of them:

  • x : x-axis value. Can be used for continuous (point, line) charts and for discrete (bar, histogram) charts.
  • y : y-axis value. Can be used for continuous charts only
  • color : color of a layer. Can be continuous or discrete. If continuous, this will be given a color gradient between 2 colors.
  • shape : shape of a point. Can be used only with geom_point
  • size : size of a point or line. Used to give a relative size for a continuous value
  • alpha : transparency level of a point. Number between 0 and 1. Only supported for hard coded values.
  • ymin : min value for a vertical line or a range of points. See geom_area, geom_ribbon, geom_vline
  • ymax : max value for a vertical line or a range of points. See geom_area, geom_ribbon, geom_vline
  • xmin : min value for a horizonal line. Specific to geom_hline
  • xmax : max value for a horizonal line. Specific to geom_hline
  • slope : slope of an abline. Specific to geom_abline
  • intercept : intercept of an abline. Specific to geom_abline

In [2]:
# set the x-axis equal to the `date` column and the y-axis equal to the `beef` column
my_aes = aes(x='date', y='beef')
my_aes


Out[2]:
{'y': 'beef', 'x': 'date'}

In [3]:
ggplot(meat, my_aes) + geom_line()


Out[3]:
<ggplot: (288207577)>

In [4]:
# normally, aes are defined within the `ggplot` constructor
ggplot(aes(x='carat', y='price'), diamonds) + geom_point()


Out[4]:
<ggplot: (288335565)>

In [5]:
# adding in another aesthetic into the mix...
ggplot(aes(x='carat', y='price', color='clarity'), diamonds) + geom_point()


Out[5]:
<ggplot: (288823329)>

In [ ]: