I was wondering how I could overlay two scatter plots in one plot. The
reason I ask is I have two different data sets and I would like to
overlay them on top of each other. Is it possible to do that? I tried
to create two ggplot objects ('p' and 'd') and then do
p + d + geom_point()
but I am not sure if that s the right way to do this. Another problem
with this approach is I am not sure how to use scale_colour_brewer
function for each one separately.
thanx
Anatole
I think it works like this: given dat1 and dat2 are dataframes with
the same varables X and Y,
p <- ggplot(dat1, aes(x=X, y=Y)) + geom_point()
p + geom_point(data=dat2)
But it's almost always better to put the data in the same data.frame:
dat <- rbind(dat1, dat2)
dat$dataset <- factor(c(rep("dat1", dim(dat1)[1]), rep("dat2", dim(dat2)[1])))
ggplot(dat, aes(x=X, y=Y, shape=dataset)) + geom_point()
-Ista
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
>
> To unsubscribe from this group, send email to ggplot2+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
thanx again,
Anatole
ggplot(dat, aes(x=X, y=Y, color=dataset)) + geom_point()
-Ista
The code you wrote for me will only make americans blue and hispanics
red but it wont solve the shades of colors within each group. Any idea
what I can do?
thanx
anatole
qplot(x, y, data=df, colour = american.or.hispanic, alpha = body.weight)
perhaps you also want to look at scale_gradient2 (by encoding body
weights of the two groups to two gradients)?
Xie Chao
best,
Anatole
On Mar 24, 1:22 am, Xie Chao <xiech...@gmail.com> wrote:
> how about:
>
> qplot(x, y, data=df, colour = american.or.hispanic, alpha = body.weight)
>
> perhaps you also want to look at scale_gradient2 (by encoding body
> weights of the two groups to two gradients)?
>
> Xie Chao
>
Yes, but you are asking for a bizarre plot in which will make it
difficult to compare the weights of different races. You have not said
why you want both race and colour to be mapped to colour instead of
using size and colour or shape and colour, either of which would be
easier to read.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
Best,
baptiste
I hope that explains why I am trying to do what I was asking people
earlier.
Best,
Anatole
On Mar 24, 9:15 am, baptiste auguie <bapt4...@googlemail.com> wrote:
> It seems to me that the hcl colour scale (issue #26http://github.com/hadley/ggplot2/issuesearch?state=open&q=scale#issue/26
> ) could help for this particular problem. One variable would be mapped
> to hue, the other one to chroma for example. I wonder if this concept
> could be extended to other colour scales such as scale_gradient_n,
> following different paths in the colour space.
>
> Best,
>
> baptiste
>
If you want, I think, you can customize.
But this seems to be an old-fashioned way,
and you may not take advantage of user-friendly-ness of ggplot2.
dat<-data.frame(g=gl(2,25),x=runif(50),y=runif(50),z=runif(50),n=factor(1:50))
b<-colorRamp(c("#0000FF","#DDDDFF"), space="rgb", interpolate="linear")
g<-colorRamp(c("#00FF00","#DDFFDD"), space="rgb", interpolate="linear")
col.fun<-list(b,g)
col<-c()
for(g. in 1:2){
col<-c(col,nice_ramp(col.fun[[g.]],subset(dat,g==g.)$z))
}
dat$col<-col
ggplot(dat,aes(x=x,y=y,colour=n,shape=g))+geom_point()+scale_colour_manual(value=col)+opts(legend.position="none")
HTH.
2010/3/25 Anatole <agha...@ucla.edu>:
On Mar 24, 10:26 am, takahashi kohske <takahashi.koh...@gmail.com>
wrote:
> Hi,
>
> If you want, I think, you can customize.
>
> But this seems to be an old-fashioned way,
> and you may not take advantage of user-friendly-ness of ggplot2.
>
> dat<-data.frame(g=gl(2,25),x=runif(50),y=runif(50),z=runif(50),n=factor(1:50))
>
> b<-colorRamp(c("#0000FF","#DDDDFF"), space="rgb", interpolate="linear")
> g<-colorRamp(c("#00FF00","#DDFFDD"), space="rgb", interpolate="linear")
>
> col.fun<-list(b,g)
> col<-c()
> for(g. in 1:2){
> col<-c(col,nice_ramp(col.fun[[g.]],subset(dat,g==g.)$z))}
>
> dat$col<-col
>
> ggplot(dat,aes(x=x,y=y,colour=n,shape=g))+geom_point()+scale_colour_manual(value=col)+opts(legend.position="none")
>
> HTH.
>
> 2010/3/25 Anatole <aghaz...@ucla.edu>:
weird, it should take you to the bug (feature) report page. At any
rate, the hcl colour scale is not yet implemented (as far as I know).
I tried to write one but I must be missing something basic as I can't
get it to work with more than one variable :(
In fact, ggplot2 support quite a number colour_gradient scales, for
example scale_gradient2. With proper encoding, you can easily
implement your plot without creating manual colours:
df <- data.frame(g=gl(2,25),x=runif(50),y=runif(50),z=runif(50))
df <- transform(dat, gz = (as.numeric(g)-1.5) * 2 * (z + 0.5))
qplot(x, y, data=df, colour=gz) + scale_colour_gradient2()
Then you can set the gradient breaks and re-label them with
un-transformed/decoded value + grouping.
Hope this can change your impression on ggplot2.
Xie Chao
I think I have come across incorrectly. As an R user I am a huge fan
of ggplot2 and I just want to tell the developers how much I
appreciate it.
In terms of the code you sent me I had a question: basically you re
suggesting to code the two datasets as 1 and -1 and multiply these
values to the quantitative trait which I want to use as gradient
coloring. Makes perfect sense and I think it s simple but very clever.
What I dont understand is why are you adding 0.5 to z in the following
code:
gz = (as.numeric(g)-1.5) * 2 * (z + 0.5)
...Instead, wouldnt it suffice to say
gz = (as.numeric(g)-1.5) * 2 * z
I think this will do the job too unless you had a reason to add the
0.5 increment to z.
thanx
anatole
On Mar 24, 6:51 pm, Xie Chao <xiech...@gmail.com> wrote:
The 0.5 is used to avoid using the middle color.
without the 0.5 (or any non-zero number), you will not distinguish
value 0 for group a and group b. For example:
(1 - 1.5) * 2 * 0 = 0
(2 - 1.5) * 2 * 0 = 0
then both values are represented the middle colour, or white.
But after add the 0.5:
(1 - 1.5) * 2 * (0 + 0.5) = - 0.5
(2 - 1.5) * 2 * (0 + 0.5) = +0.5
Of course if you know there is no zero value in your data, it will be
much easier to not add the 0.5.
(and sorry for misunderstood your message..)
Xie Chao
Yes you re right...there are no zeros in the data, in fact they all
start at 5 or up. But thanx for clarifying it.
On Mar 24, 10:35 pm, Xie Chao <xiech...@gmail.com> wrote: