Skip to content
Prev 262540 / 398502 Next

smoothScatter function (color density question) and adding a legend

----------------------------------------
Thanks, I was curious about this and so I installed the geneplot package
and that went fine but I had another issue and need to take care of that.
First, see if "?legend" helps at all ( no idea, I have not used this stuff much).
Also source code should be available for the pacakge you care about.


On quick read, it sounds like this uses a binning system for colors. If you
want something slightly different and much slower, I have some examples
( IIRC) that calculate densities in R using something similar to electric
field calculation around points, ( again I'm in a hurry and pulling this
from archive so caveat emptor this plot may not correspond exactly to
example script below etc), 


http://98.129.232.232/coloumb1.pdf


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); } 
# coloumb is a bit much with overlapping data points, so limite it a bit
z[y]=sum(1.0/(.001*1+(x1[nx]-x1[y])*(x1[nx]-x1[y])+(x2[nx]-x2[y])*(x2[nx]-x2[y]))); 
#for
}
print(max(z));
print(min(z));
z=z-min(z);
z=100*z/max(z);
hist(z);
color=rainbow(100);
#color=heat.colors(10);
tmap=color[floor(z)+1];
scatterplot3d(x1,x2,z,color=tmap);
plot(x2,x1,col=tmap,cex=.5)
#library("VecStatGraphs2D")
#DrawDensityMap(x1,x2,PaintPoint=TRUE)
#color=terrain.colors(26)
#color=heat.colors(26)

}