1

I have three data series which are composed of :

  • X (float)
  • Y (float)
  • S (float)
  • Class (discrete values)

All three data series are sharing the same X coordinate but every other component is different from each other data series. By using one geom_point() for each of my three data series (the library ggpplot2 in R) I would like to plot each of the data series with a color scale according to it specific S as follow :

ggplot(data, aes(x=X)) + geom_point(aes(y=Y, colour=S, shape=Class)) 

This works if I am using only one data series. The problem is that if I define three geom_points() as specified using their own Y and S, they all have the same color scale and this is a bit confusing on the plot.

As I am already using the shapes to distinguish between the Classes I would really enjoy to have a specific color with its own color gradient for each of my data series .

Lets say for example :

  • from dark blue to light blue for the data series 1
  • from dark red to light red for the data series 2
  • from dark yellow to light yellow for the data series 3

I looked around but I haven't found anything satisfying my needs. Some comments where saying that using ggplot2 it is not possible to have more than one color scale per plot... Is it true ?

If anyone has already figured out this kind of plot with or without ggplot2 I would greatly appreciate his or her solution.

thelatemail
  • 91,185
  • 12
  • 128
  • 188
Gasteiger
  • 11
  • 2
  • As far as I know, this is still not available in ggplots, and I'm pretty sure Hadley said it won't be any time soon. – N8TRO Mar 05 '13 at 01:13
  • Thank you Nathan, i'll have a better look around here next time. I just discovered the website and i'm sure it is really usefull – Gasteiger Mar 05 '13 at 01:41
  • some time ago there was a discussion of a 2D colour scale, where you could map hue, chroma, luminance. This would be one use case, still keeping with the grammar framework. I'm not sure how far @kohske went in the implementation. – baptiste Mar 05 '13 at 06:14

1 Answers1

1

In ggplot you can really only use alpha for what you're asking. I've made up some data:

df1 <- data.frame(X=rnorm(16), Y=rnorm(16), S=rep(1:4,times=4), Class=rep(LETTERS[1:4], each=4))
df2 <- data.frame(X=rnorm(16), Y=rnorm(16), S=rep(1:4,times=4), Class=rep(LETTERS[1:4], each=4))
df3 <- data.frame(X=rnorm(16), Y=rnorm(16), S=rep(1:4,times=4), Class=rep(LETTERS[1:4], each=4))

ggplot(df1, aes(x)) + geom_point(aes(y=Y, colour=S, shape=Class))
df1$id <- 1
df2$id <- 2
df3$id <- 3
df.list <- list(df1, df2, df3)
df.all <- ldply(df.list, rbind)

ggplot(df.all, aes(X, Y)) + geom_point(aes(colour=as.factor(id), shape=Class, alpha=S))

Not sure if that meets your requirements...

alexwhan
  • 15,636
  • 5
  • 52
  • 66
  • Just saw @Nathan G's comment on your question - wasn't aware of duplicate issue... I guess the only difference here is that the datasets are in different dataframes, as opposed to different columns in the one dataframe - ends up with the same solution though. – alexwhan Mar 05 '13 at 01:26
  • Actually, there are many questions on this subject already. You answered pretty well, but I might use `size` instead of `alpha`. I really wouldn't mind seeing a grid solution. – N8TRO Mar 05 '13 at 01:29
  • It is indeed a useful trick to know about ggplot2. Your answers helped me a lot. Thank you again – Gasteiger Mar 05 '13 at 01:55