[R] re-arranging data to create an image (or heatmap)
Mike Marchywka
marchywka at hotmail.com
Mon Feb 28 19:18:05 CET 2011
ok, third try. This is a repost of a message never made it
past mod as I cancelled while it was waiting to clean up some
code to at least make it close to working.
I think this does more or less what you want,
> library("VecStatGraphs2D")
>
> DrawDensityMap(x1,x2,PaintPoint=TRUE)
but if not see the function below that
while clumsy does seem to color about as I would
expect given the density function I created.
again, "for illustration only" don't use for
life support system or nuclear power plants etc.
----------------------------------------
> From: marchywka at hotmail.com
> To: s.piersma at gmail.com; r-help at r-project.org
> Subject: RE: [R] re-arranging data to create an image (or heatmap)
> Date: Mon, 28 Feb 2011 11:47:30 -0500
>
>
>
>
>
>
>
>
>
>
> ----------------------------------------
> > Date: Mon, 28 Feb 2011 08:23:41 -0800
> > From: s.piersma at gmail.com
> > To: r-help at r-project.org
> > Subject: Re: [R] re-arranging data to create an image (or heatmap)
> >
> > Thank you for your quick reply. The change in transparency makes a big
> > difference. I will have a look at the other packages to see if i can do
> > multiple colors.
>
> This is a problem has has been bugging me for a while now but I hadn't searched
> for a solution. However, it does seem that google on 'R "point density" CRAN'
> turns up an intersting packaged called "VecStatGraph2D." I used the sample in the
> docs and it doesn't color the points but maybe it will work for you, I plan on using
> it soon,
>
> x1=rnorm(1000)
> x2=rnorm(1000)
> plot(x2,x1)
>
> library("VecStatGraphs2D")
>
> DrawDensityMap(x1,x2,PaintPoint=TRUE)
>
> history(500)
>
>
> However, if you can find a density measure of you own, you an play with this.
> Perhaps an R person can remove the loops and other kluges but generally you just
> want to make a color table and pick from that for your plotting. For example,
> assume that each point creates a 1/r^2 density and then add up the density at
> each point ( would appreciate a cleaner way to do this with or without snide comments
> LOL),
>
>
mydensity<-function(x1,x2)
{
len=length(x1);
z<-1:len;
for ( y in 1:len )
{
nx=c(1:(y-1),(y+1):len);
if ( y==1) {nx=2:len;}
if (y==len) {nx=1:(len-1); }
z[y]=sum(1.0/(.0001+(x1[nx]-x1[y])*(x1[nx]-x1[y])+(x2[nx]-x2[y])*(x2[nx]-x2[y])));
#for
}
z=sqrt(z);
z=sqrt(z);
print(max(z));
print(min(z));
z=z-min(z);
z=10*z/max(z);
hist(z);
color=rainbow(10);
#color=heat.colors(10);
tmap=color[floor(z)+1];
scatterplot3d(x1,x2,z,color=tmap);
plot(x2,x1,col=tmap)
#library("VecStatGraphs2D")
#DrawDensityMap(x1,x2,PaintPoint=TRUE)
#color=terrain.colors(26)
#color=heat.colors(26)
}
>
>
> >
> >
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/re-arranging-data-to-create-an-image-or-heatmap-tp3327986p3328227.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > 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.
>
More information about the R-help
mailing list