Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow several simultaneous colour scales #578

Closed
jiho opened this Issue · 4 comments

4 participants

@jiho

While we think about reorganizing scale_colour/fill functions in pull request #439, here is an additional suggestion:

I think it would be worthwhile to have a variable argument to the scale functions, which would determine to which variable the scale applies and would therefore enable having several colour (or shape, or ...) scales on the same plot for various variables. Of course this can be a problem perceptually (if the colour scales are too similar) but it can also be efficient and even required to represent complex data sets.

Consider graphs like this: http://ars.els-cdn.com/content/image/1-s2.0-S1053811912001255-gr2.jpg where there are various colour scales for various data sources (regions of the brain in that case).
Or maps like this: http://comlmaps.org/mcintyre/ch11/image_n/nfg003.jpg/image_preview (sorry, quite small) with a blue scale for depth and another scale (green to red) for species abundance.

Here is a practical example

library(reshape2) # for melt

# volcano map, which really is the background of the plot
vd <- melt(volcano)
names(vd) <- c("x", "y", "z")

# point measurements of something (abund) at a few locations
d <- data.frame(x=runif(30, 1, 80), y=runif(30, 1, 60), abund=rnorm(30))

# plot the points on top of the map
ggplot(mapping=aes(x=x, y=y)) + geom_tile(aes(fill=z), data=vd) + geom_point(aes(colour=abund), data=d, size=3) + scale_colour_gradient(high="red", low="green")
# this works because I map *fill* in one geom and *colour* in the other

# but this collapses the scales of the background and the points because both use fill
ggplot(mapping=aes(x=x, y=y)) + geom_tile(aes(fill=z), data=vd) + geom_point(aes(fill=abund), data=d, size=3, shape=21) + scale_fill_gradient(high="red", low="green")

# I would like to do
ggplot(mapping=aes(x=x, y=y)) + geom_tile(aes(fill=z), data=vd) + geom_point(aes(fill=abund), data=d, size=3, shape=21) + scale_fill_gradient(variable=abund, high="red", low="green")
# and get a result similar to the first plot above
@oscarbranson

A quick +1 for this feature. Being able to assign colour scales to variables separately would be enormously useful.

For example, being able to build up a composite plot or image by plotting semi-transparent layers with different colour scales.

@khughitt

+1

This would be useful, for example, to overlay a segmented line fit on top of a scatter plot, each with their own color scales.

@hadley
Owner

This sounds like a great feature, but unfortunately we don't currently have the development bandwidth to support it. If you'd like to submit a pull request that implements this feature, please follow the instructions in the development vignette.

@hadley hadley closed this
@hadley
Owner

(btw ggvis supports this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.