Skip to content

ggplotly design, internals, technical stuff

Carson edited this page Aug 1, 2015 · 7 revisions

converting the group aesthetic

In ggplot2 the group aesthetic is used to designate separate lines, polygons, paths, ribbons (but not points) that all look the same. For example in the canada cities viz the borders are a geom_polygon with aes(group).

> borders(regions="canada", name="borders")
mapping: x = long, y = lat, group = group 
geom_polygon: colour = grey50, fill = NA 
stat_identity: name = borders 
position_identity: (width = NULL, height = NULL)

It is important that this is translated as 1 trace with NAs (not a separate trace for each lake/island), because

  • it is much more efficient (the plotly web site is slow when there are many traces to render).
  • each trace gets its own legend entry and it doesn't make sense to have separate legend entries for each one of the lakes/islands/etc.

A test for this functionality is here

legends

ggplot2 legends are more sophisticated than plotly legends, so it is impossible to translate everything. In particular there may be several legends in ggplot2 (color, linetype, etc) but only 1 in plotly. Plotly takes the legend labels from the names of the traces.