Hi,

Try this.
Sincelery,

Marc

x <- rnorm(128, 10, 2)
y <- rnorm(128, 10, 2)

z <- x+y

nbcol <- heat.colors(128)

# standardize z to be from 1 to 128
zcol <-  ((z-min(z))/(max(z)-min(z)))*127+1

library(scatterplot3d)
library(fields)

scatterplot3d(x,y,z, pch=16,color=nbcol[zcol], grid=FALSE, box=FALSE, 
mar=c(5, 3, 5, 7)+0.1)

par(mar=c(5, 4, 4, 2) + 0.1)

image.plot( legend.only=TRUE, zlim= c(min(z), max(z)), nlevel=128, 
col=heat.colors(128))




Le 13/03/13 17:36, Zhuoting Wu a écrit :
> Thanks Marc! I tried the colorbar.plot and image.plot.
>
> The colorbar.plot gives color bars within the plot, but I want a color 
> bar legend on the side of the plot.
>
> The image.plot gives a legend that overlaps the plot, and the scale 
> doesn't match the 3d scatterplot at all (see attached).
>
> Here's my R script:
>
> cols <- myColorRamp(c(topo.colors(10)),z)
> scatterplot3d(x,y,z, pch=16,color=cols, grid=FALSE, box=FALSE)
> zr<- range(c(z))
> image.plot(legend.only=TRUE,col=cols, zlim=zr)
>
> I wanted to have a color ramp legend based on z on the side of the plot.
>
> I'll greatly appreciate any help!
>
> thanks,
> Z
>
> On Wed, Mar 13, 2013 at 2:11 AM, Marc Girondot <marc_grt@yahoo.fr 
> <mailto:marc_grt@yahoo.fr>> wrote:
>
>     Le 12/03/13 23:43, Zhuoting Wu a écrit :
>     > I have a 3 column dataset x,y,z, and I plotted a 3d scatter plot
>     using:
>     >
>     > cols <- myColorRamp(c(topo.colors(10)),z)
>     > plot3d(x=x, y=y, z=z, col=cols)
>     >
>     > I wanted to add a legend to the 3d plot showing the color ramp.
>     Any help
>     > will be greatly appreciated!
>     >
>     >
>     Look at the package fields:
>     ?colorbar.plot
>
>     Marc
>
>     --
>     __________________________________________________________
>     Marc Girondot, Pr
>
>     Laboratoire Ecologie, Systématique et Evolution
>     Equipe de Conservation des Populations et des Communautés
>     CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
>     Bâtiment 362
>     91405 Orsay Cedex, France
>
>     Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
>     e-mail: marc.girondot@u-psud.fr <mailto:marc.girondot@u-psud.fr>
>     Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
>     Skype: girondot
>
>
>             [[alternative HTML version deleted]]
>
>
>     ______________________________________________
>     R-help@r-project.org <mailto:R-help@r-project.org> mailing list
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     PLEASE do read the posting guide
>     http://www.R-project.org/posting-guide.html
>     and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
__________________________________________________________
Marc Girondot, Pr

Laboratoire Ecologie, Systématique et Evolution
Equipe de Conservation des Populations et des Communautés
CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
Bâtiment 362
91405 Orsay Cedex, France

Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.girondot@u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot


	[[alternative HTML version deleted]]

