Skip to content
xuexue edited this page Jul 31, 2012 · 6 revisions

Layers represent different chart types that can be drawn (equivalent to ggplot's "geometry"). Layers can be added to gg.graph objects using the addLayer function, and are rendered when the gg.graph.render() function is called.

  • gg.layer.area - area chart
  • gg.layer.bar - bar chart
  • gg.layer.box - box-plot
  • gg.layer.line - line chart
  • gg.layer.path - path chart
  • gg.layer.point - scatter plot
  • gg.layer.text - text
  • gg.layer.tile - tiles

Calling gg.layer.*() (e.g. gg.layer.box()) creates a new layer object, which can be attached to graph objects. The constructor takes an optional data parameter defining the data to plot. If the data parameter is not present, the default data bound to the parent gg.graph object will be used.

Bind a data object to plot in place of the default data bound to the parent gg.graph object.

Map an aesthetic to a variable in the data set. An aesthetic is a feature of the geometric objects that represent the data. For example, map('x', 'var1') would mean that the x-position in the plot will depend on the variable 'var1' in the bound data set. As another example, map('color', 'var2') tells Polychart that color of objects plotted by the layer should depend on 'var2'. Here's a list of all the aesthetics:

  • x -- the x-position
  • y -- the y-position
  • color -- the most prominent color of a layer (fill or stroke)
  • fill -- the fill color
  • stroke -- the outline/stroke color
  • strokewidth -- width of the outline/stroke
  • opacity -- opacity of the fill color
  • size -- the size of objects
  • symbol -- the symbol to plot (for points)
  • radius -- the radius of points (for points)
  • text -- the text to display (for text)
  • font -- the font of text elements (for text)
  • fontsize -- the font size of text elements (for text)

One can pass in an associate array of aesthetic to variable mappings as opposed to calling map multiple times.

Map an aesthetics to a constant value. The list of aesthetics is the same as above. As above one can pass in an associate array of aesthetic to constants as opposed to calling opts multiple times.

Set the statistics to run on the data prior to rendering. The stats parameter can be a string or a gg.stats object. A statistics pre-processes the data before rendering it (e.g. take the count of some values, etc).

Clone this wiki locally