Skip to content
Back to formatted view

Raw Message

Message-ID: <4EA15AB0.4050607@bitwrit.com.au>
Date: 2011-10-21T11:42:40Z
From: Jim Lemon
Subject: Scatterplot with the 3rd dimension = color?
In-Reply-To: <9729b67c-67cd-4319-bbae-9374ad1ad3fa@z26g2000yqh.googlegroups.com>

On 10/21/2011 06:25 AM, Kerry wrote:
> Can someone please help me out with this? The ggplot2 suggestion works
> great but I've spent a few days trying to figure out how to plot 2
> variables with it and I'm stuck. Here's my example code:
> ...

Hi Kerry,
This isn't ggplot2, but it may do what you want.

library(plotrix)
oldmar<-par(mar=c(5,4,4,4))
plot(x,y,type="n")
plotlim<-par("usr")
rect(plotlim[1],plotlim[3],plotlim[2],plotlim[4],col="lightgray")
grid(col="white")
box()
points(x,y,col=color.scale(z,c(1,0),0,c(0,1)),pch=19)
points(x1,y2,col=color.scale(z3,1,c(0,1),0),pch=19)
legendval1<-seq(min(z),max(z),length.out=5)
color.legend(2.9,0.5,3.1,1.5,round(legendval1,1),align="rb",gradient="y",
  rect.col=color.scale(legendval1,c(1,0),0,c(0,1)))
legendval2<-seq(min(z3),max(z3),length.out=5)
color.legend(2.9,-1.5,3.1,-0.5,round(legendval2,1),align="rb",gradient="y",
  rect.col=color.scale(legendval2,c(1,1),c(0,1),0))
par(xpd=TRUE)
text(3,1.6,"z")
text(3,-0.4,"z3")
par(xpd=FALSE,oldmar)

Jim