Here's a simple example of a dataset this could be useful on:
n=16
x=rnorm(n)
y=rnorm(n)
l=c(3,5,n-8)
time=unlist(lapply(l,seq_len))
z=rep(letters[1:3],l)
d=data.frame(x,y,z,time)
qplot(x,y,colour=z,group=z,size=I(3),geom="path")
This draws three paths of different lengths and colours. If 'x' and y
'is' position and 'time' is time (either absolute or relative), it
would useful to use the lightness to indicate time, where the old
positions fade away. (An alternative is to use 'alpha', but for
various reasons I prefer not too.)
So, is this possible?
There is in fact two useful ways the lightness could be mapped. One
uses an absolute scale, so that time = 1 is lightest and time = 8 is
darkest (which should be the colour the above code now gives us, not
black). Then all of short pink line will be very light. This is the
way 'size=time' works.
The other one is based on a relative scale, e.g., a scale for each
group. Then the start of the pink line will be very light (e.g.
white), and the end will have full colour.
Both alternatives will be useful in different circumstances.
--
Karl Ove Hufthammer
> I just uploaded an experimental version here,
>
> source("http://ggextra.googlecode.com/svn/trunk/inst/tests/colour-luminance.r")
>
> dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
> d <- qplot(carat, price, data=dsamp, colour=clarity)
>
> d + scale_colour_luminance()
Thanks. It works fine for setting the luminance based on the 'colour'
aesthetic, but that's not what I need; I wish to set the hue based on
the 'colour' aesthetic and set the luminance based on a different
('luminance') aesthetic, so that one line (in my original example) is
pink with various luminance values, one is green with various
luminance values, and one is blue with various luminance values.
In other words, the hue and the luminance should be set independently,
just like colour and size and alpha can be.
--
Karl Ove Hufthammer
> In other words, the hue and the luminance should be set independently,
> just like colour and size and alpha can be.
>
> --
> Karl Ove Hufthammer
>
As far as I understand you'd need to modify most if not all existing
geoms to add this new luminance aesthetic, and you would also have to
deal with the interaction between colour and luminance. (presumably by
converting the colour and fill to hcl in all geoms). Let's hope I
missed something more obvious.
baptiste
ggplot2 definitely has the capability for scales to have multiple
input variables for a single output. I don't think there are any
scales that currently do this, but I did use to have a scale where you
could map variables to hue, chroma and luminance separately. I ended
up taking it out because it was very difficult to create useful plots
with it.
Hadley
That makes sense, there is no need to modify other scales as I wrongly
hypothesized.
As far as I understand though, such a scale would require adding a
"luminance" parameter to all relevant geoms, right?
baptiste
No, because the scale would emit the colour aesthetic. It's a
different situation to alpha, because colour and alpha are
independent, while luminance and hue both contribute to colour.
Hadley
scales that currently do this, but I did use to have a scale where you
could map variables to hue, chroma and luminance separately. I ended
up taking it out because it was very difficult to create useful plots
with it.