Alpha version of colorbar legend in ggplot2


The examples below show colorbar legends in ggplot2.

Please note that this is alpha version and it is not sure if this implementation appears in the future version of ggplot2.

I’m happy if you play with this function and report potential bugs and missing functions.

To test this, you need install Hadley’s scales package and my implementation based on Hadley’s ggplot2.

Here is a direct link to the tarball:

The colorbar is controlled by passing the legend_param argument to scale_{fill, colour}_XXX. XXX needs to be continuous family, e.g., discrete, etc.

The legend_param needs to be a list. Currently three elements is available.

  1. colorbar (logical): draw colorbar if TRUE.
  2. colorbar_nbin (integer): the number of division of colorbar, i.e., the resolution of the colorbar default: approx. 20).
  3. colorbar_nbreaks (integer): the number of breaks of the colorbar (default: approx. 5).

The size of colorbar is controlled by theme – legend.key.size, legend.key.width, and legend.key.height.

The breaks and labels can be controlled via breaks and labels arguments in scale_*, this is same as normal legend.

Continue reading