Motivation
nplot() can now map several aesthetics from graph attributes at once — color (vertex.color = ~ attr), shape (vertex.nsides = ~ attr), and size (vertex.size = ~ attr). Currently, only a single color legend is drawn automatically on print():
- discrete color → a categorical key (packed to the side of the graph), and
- continuous color → a color bar (overlaid in the top-right corner).
There are two limitations worth addressing as a dedicated feature:
-
Placement is not user-controllable. The categorical key is packed to the left and the continuous color bar is fixed in the top-right corner. Users should be able to choose where each legend goes (corner, side, outside the plotting region, custom coordinates), and toggle each on/off.
-
Only color gets a legend. When shape and/or size are also mapped from attributes, there is no legend explaining them. Ideally nplot() would compose multiple legends (color + shape + size), each of which the user can arrange independently, without them overlapping each other or the graph.
Possible direction
- A
legend/legends argument (or a nplot_legend()-style builder) that accepts per-aesthetic placement specs.
- Reuse the existing
nplot_legend() (grid packGrob framing) and colorkey() machinery, generalized to pack more than one legend and to accept a position/side/coordinates argument.
- A size legend (a few representative bubbles) and a shape legend (a few representative polygons), analogous to the color key.
Context
This came out of the work in #19 (documentation + formula/legend improvements). The discrete-vs-continuous color-legend detection and the continuous color bar were implemented there; this issue tracks the more advanced, flexible arrangement of legends for color, size, and shape together.
Motivation
nplot()can now map several aesthetics from graph attributes at once — color (vertex.color = ~ attr), shape (vertex.nsides = ~ attr), and size (vertex.size = ~ attr). Currently, only a single color legend is drawn automatically onprint():There are two limitations worth addressing as a dedicated feature:
Placement is not user-controllable. The categorical key is packed to the left and the continuous color bar is fixed in the top-right corner. Users should be able to choose where each legend goes (corner, side, outside the plotting region, custom coordinates), and toggle each on/off.
Only color gets a legend. When shape and/or size are also mapped from attributes, there is no legend explaining them. Ideally
nplot()would compose multiple legends (color + shape + size), each of which the user can arrange independently, without them overlapping each other or the graph.Possible direction
legend/legendsargument (or anplot_legend()-style builder) that accepts per-aesthetic placement specs.nplot_legend()(gridpackGrobframing) andcolorkey()machinery, generalized to pack more than one legend and to accept aposition/side/coordinates argument.Context
This came out of the work in #19 (documentation + formula/legend improvements). The discrete-vs-continuous color-legend detection and the continuous color bar were implemented there; this issue tracks the more advanced, flexible arrangement of legends for color, size, and shape together.