Hi, Would like to make an image however the values in z are not on an uniform grid. Have a dataset with length(x) == length(y) == length(z) x[1],y[1] gives the position of z[1] and would like to encode value of z by a color. looking for something like plot(x,y, col = z) where col for z is cleverly chosen from a colorscale. Hope I made clear what I am looking for. Thanks Eryk
Hi, Not really sure what you are after, but the following plots a series of points of varying colour plot(x,y,type='n') apply(cbind(x,y,z),1,function(a) {points(a[1],a[2],col=a[3],pch=".")}) but its going to be really slow for a large number of points Martyn -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of W Eryk Wolski Sent: 06 August 2010 15:25 To: r-help at r-project.org Subject: [R] image plot but data not on grid. Hi, Would like to make an image however the values in z are not on an uniform grid. Have a dataset with length(x) == length(y) == length(z) x[1],y[1] gives the position of z[1] and would like to encode value of z by a color. looking for something like plot(x,y, col = z) where col for z is cleverly chosen from a colorscale. Hope I made clear what I am looking for. Thanks Eryk ______________________________________________ R-help at 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. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}}
On Aug 6, 2010, at 10:24 AM, W Eryk Wolski wrote:> Hi, > > Would like to make an image > however the values in z are not on an uniform grid. > > Have a dataset with > length(x) == length(y) == length(z) > x[1],y[1] gives the position of z[1] > > and would like to encode value of z by a color. > > looking for something like > plot(x,y, col = z) > where col for z is cleverly chosen from a colorscale.?palette ??palette # for other coloring options ?colorRamp # random integer index from default palette for coloring of random x,y points: plot(rnorm(20), rnorm(20), col=palette()[ runif(20, 1,10) ] ) # The cleverness is left to you. -- David Winsemius, MD West Hartford, CT
On Fri, Aug 6, 2010 at 9:24 AM, W Eryk Wolski <wewolski at gmail.com> wrote:> Hi, > > Would like to make an image > however the values in z are not on an uniform grid. > > Have a dataset with > length(x) == length(y) == length(z) > x[1],y[1] gives the position of z[1] > > and would like to encode value of z by a color. > > looking for something like > plot(x,y, col = z) > where col for z is cleverly chosen from a colorscale.library(ggplot2) qplot(x, y, fill = z, data = df, geom = "tile") Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/