yhat/ggplot — pull request #378 by anthonytw (2014-10-10 20:24:34+00:00)
Title: Implemented a baseline geom_tile.

This was made to address #301 by adding some basic capability.
It doesn't completely address #293 since I was lazy and didn't
write any unit tests. :-)

The tile geom now creates a tiled geom similar to R ggplot2 with
some caveats:

- If you add the fill parameter to the ggplot aes wrapper, ggplot
will arbitrarily map colors without taking into account ordering
of the fill values, which can't (as far as I know) be stopped
by the geom coming down the pipe. If sent this way, the geom gets
the already mapped fill values and is unable to recover their
numeric values to make a heat map image, so all geom_tile plots
drawn like this are deemed 'categorical'.

- If you add the fill parameter to geom_tile's aes wrapper, the
actuall fill values are sent, so geom_tile can use them to make
a heatmap. This is the only way to do that.

- If you want to set the color range for a heat map, you have to
do it before sending the geom.

So as far as useability is concerned:
- If you want to tile categorical data, you must put the fill in
the ggplot aes.
- If you want to make a heat map, you must put the fill in the
geom aes.
- For heat maps, send color gradients before the geom.

(Technically one can get around the first restriction by duplicating
code in the geom, but I chose to issue an Exception instead to avoid
duplicating code).

Some examples of use:

# For categorical data, put in the ggplot aes wrapper.
ggplot(aes(x='x', y='y', fill='fill'), data=df) + geom_tile()

# For a heat map, put in geom aes wrapper.
ggplot(aes(x='x', y='y'), data=df) + geom_tile(aes(fill='fill'))

# If fill is sent in both wrappers, a categorical view will be
# chosen.

# Send color gradients for the heat map first.
ggplot(aes(x='x', y='y'), data=df) + scale_color_gradient(low='blue', mid='white', high='red') + geom_tile(aes(fill='fill'))