[R-sig-Geo] ramping four color in xy space

Holger Kreft hkreft at ucsd.edu
Wed Nov 19 08:33:06 CET 2008


Dear Tom,

Thanks a lot for your swift reply. While your script wasn't exactly 
doing what I wanted, it brought me on the right track. Here is the code 
that I finally used.
Probably not super elegant, but it does the job and I thought it be 
useful for others.

Cheers,

Holger

--

my.data<-seq(0,1,.01)

my.class<-classIntervals(my.data,n=100,style="equal")
my.pal.1<-findColours(my.class,c("yellow","red"))
my.pal.2<-findColours(my.class,c("green","blue"))

plot(rep(0,101),my.data,pch=19,col=my.pal.1, cex=1, xlim=c(0,1),ylim=c(0,1))
points(rep(1,101),my.data,pch=19,col=my.pal.2, cex=1)

#------------------------------------
# loop: use left and right vertical
# color ramp & interpolate horizontally
#------------------------------------

col.matrix<-matrix(nrow = 101, ncol = 101, NA)

for(i in 1:101){
my.col<-c(paste(my.pal.1[i]),paste(my.pal.2[i])) # choose colors
col.matrix[102-i,]<-findColours(my.class,my.col)
}

#------------------------------------
# plot full grid
#------------------------------------

plot(rep(0,101),my.data,pch=19,col=my.pal.1, cex=0.5, 
xlim=c(0,1),ylim=c(0,1))

for(i in 1:101){
col.temp<-col.matrix[i-1,]
points(my.data,rep((i-1)/100,101),pch=19,col=col.temp, cex=1)
}




Tomislav Hengl schrieb:
> Dear Holger,
>
> This is a small script that uses [colorspace] library to run calculations with colors (some methods
> are limited to 256 colors only):
>
> http://spatial-analyst.net/scripts/whitening.R
>
> If you assign R,G,B values spatially and then interpolate them (they have to be in the 0-1 range),
> then it is relatively easy to produce an RGB image.
>
> cheers,
>
> Tom Hengl
> http://spatial-analyst.net/wiki/index.php?title=Uncertainty_visualization 
>
>
> PS: maybe you should also consider color mixing:
>
> Hengl T., Walvoort D.J.J., Brown A. 2004. A double continuous approach to visualisation and analysis
> of categorical maps. Int. Jou. of Geographical Information Science, 18(2): 183-202.
> http://dx.doi.org/10.1080/13658810310001620924 
>
>
> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of
> Holger Kreft
> Sent: Tuesday, November 18, 2008 9:38 AM
> To: R-sig-Geo at stat.math.ethz.ch
> Subject: [R-sig-Geo] ramping four color in xy space
>
> Hi,
>
> I have run a metaMDS(vegan) on ecological community data and have a nice 
> plot in xy space.
> What I want to do next is to assign a unique color to each point in the 
> plot and then look at how these communities map out in geographic space.
> So, each corner of the plot has a color (let's say green, blue, red and 
> yellow). I guess I have to ramp the colors for the space inbetween.
> The right plot here illustrate how the palette should look like: 
> http://www.flickr.com/photos/erniebooth/183647844/
>
> Does anyone have experience in ramping four colours in 2-D? I looked at 
> a lot of packages, but they are all not doing what I want.
>
> Any hint / help is greatly appreciated!
>
> Thanks,
>
> Holger
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>   


-- 
****************************************************************
Dr. Holger Kreft
Phone:  ++1-858-5346659
Email:  hkreft at ucsd.edu
www.uni-bonn.de/~uzsxeg
 
Ecology Behavior & Evolution Section
Division of Biological Sciences
University of California, San Diego
9500 Gilman Drive, MC 0116
La Jolla, CA 92093-0116, USA
http://www-biology.ucsd.edu/labs/jetz/




More information about the R-sig-Geo mailing list