Need frequency distribution for x,y coordinates

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Need frequency distribution for x,y coordinates

markshanks
Hi,

I have a set of data in x,y coordinates across the range of -5 to 5 in each
dimension. I would like to obtain the frequency distribution of the
different points, and then graph them so you can see which of the points are
the most frequently occurring.

This would seem to be easy in Matlab, which has the hist3 command for doing
frequency distributions/histograms in 3 dimensions. However, as far as I can
tell, R does not have a hist3 command.

Is there any easy way to do this in R? I'm investigating whether matlab or R
is more suitable for our needs, but don't want to reject R due to my present
ignorance of its functions.

_________________________________________________________________
realestate.com.au: the biggest address in property  
http://ninemsn.realestate.com.au

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Need frequency distribution for x,y coordinates

Gabor Grothendieck
Check out:

http://addictedtor.free.fr/graphiques/graphcode.php?graph=116

On 2/11/06, mark shanks <[hidden email]> wrote:

> Hi,
>
> I have a set of data in x,y coordinates across the range of -5 to 5 in each
> dimension. I would like to obtain the frequency distribution of the
> different points, and then graph them so you can see which of the points are
> the most frequently occurring.
>
> This would seem to be easy in Matlab, which has the hist3 command for doing
> frequency distributions/histograms in 3 dimensions. However, as far as I can
> tell, R does not have a hist3 command.
>
> Is there any easy way to do this in R? I'm investigating whether matlab or R
> is more suitable for our needs, but don't want to reject R due to my present
> ignorance of its functions.
>
> _________________________________________________________________
> realestate.com.au: the biggest address in property
> http://ninemsn.realestate.com.au
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Need frequency distribution for x,y coordinates

Roger Bivand
In reply to this post by markshanks
On Sat, 11 Feb 2006, mark shanks wrote:

> Hi,
>
> I have a set of data in x,y coordinates across the range of -5 to 5 in each
> dimension. I would like to obtain the frequency distribution of the
> different points, and then graph them so you can see which of the points are
> the most frequently occurring.
>
> This would seem to be easy in Matlab, which has the hist3 command for doing
> frequency distributions/histograms in 3 dimensions. However, as far as I can
> tell, R does not have a hist3 command.

See contributed package ash, function bin2:

> xy <- cbind(x=runif(250,-5,5), y=runif(250,-5,5))
> bins <- bin2(xy, ab=matrix(c(-5,-5,5,5),2,2))
> image(bins$nc)

or

> filled.contour(bins$nc)

Using the x and y arguments to image or filled.contour, you can set the
axes, and asp=1 to preserve aspect.

See also function kde2d in package MASS - included in the standard
distribution.

IMO, 3D histograms can mislead because perception depends on viewer
position. All of the above give readily interpreted visualisations based
on colour class intervals.

>
> Is there any easy way to do this in R? I'm investigating whether matlab or R
> is more suitable for our needs, but don't want to reject R due to my present
> ignorance of its functions.
>
> _________________________________________________________________
> realestate.com.au: the biggest address in property  
> http://ninemsn.realestate.com.au
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Need frequency distribution for x,y coordinates

Brian Ripley
On Sat, 11 Feb 2006, Roger Bivand wrote:

> On Sat, 11 Feb 2006, mark shanks wrote:
>
>> I have a set of data in x,y coordinates across the range of -5 to 5 in each
>> dimension. I would like to obtain the frequency distribution of the
>> different points, and then graph them so you can see which of the points are
>> the most frequently occurring.
>>
>> This would seem to be easy in Matlab, which has the hist3 command for doing
>> frequency distributions/histograms in 3 dimensions. However, as far as I can
>> tell, R does not have a hist3 command.
>
> See contributed package ash, function bin2:
>
>> xy <- cbind(x=runif(250,-5,5), y=runif(250,-5,5))
>> bins <- bin2(xy, ab=matrix(c(-5,-5,5,5),2,2))
>> image(bins$nc)
>
> or
>
>> filled.contour(bins$nc)
>
> Using the x and y arguments to image or filled.contour, you can set the
> axes, and asp=1 to preserve aspect.
>
> See also function kde2d in package MASS - included in the standard
> distribution.

And density plots are usually a lot better than histograms for
understanding 2D data.

> IMO, 3D histograms can mislead because perception depends on viewer
> position. All of the above give readily interpreted visualisations based
> on colour class intervals.

But if you really want one, see demo("hist3d") in package rgl, which
allows you to change your position interactively and uses translucency.


>> Is there any easy way to do this in R? I'm investigating whether matlab or R
>> is more suitable for our needs, but don't want to reject R due to my present
>> ignorance of its functions.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Need frequency distribution for x,y coordinates

nojhan
In reply to this post by Gabor Grothendieck
Le Sat, 11 Feb 2006 04:40:41 -0500, Gabor Grothendieck a écrit :
> http://addictedtor.free.fr/graphiques/graphcode.php?graph=116

Or hist2d, in the gplots package :
http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=70

--
NoJhan

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Need frequency distribution for x,y coordinates

Jim Lemon-2
In reply to this post by markshanks
mark shanks wrote:
 >
 > Hi,
 >
 > I have a set of data in x,y coordinates across the range of -5 to 5
in each
 > dimension. I would like to obtain the frequency distribution of the
 > different points, and then graph them so you can see which of the
points are
 > the most frequently occurring.
 >
 > This would seem to be easy in Matlab, which has the hist3 command for
doing
 > frequency distributions/histograms in 3 dimensions. However, as far
as I can
 > tell, R does not have a hist3 command.

If a 2D display is okay, you can use the color2D.matplot function in the
plotrix package to plot the output of something like kde2d in MASS:

x<-seq(-5,5,by=0.1)
xdens<-kde2d(sample(x,500,TRUE),sample(x,500,TRUE),n=11)
color2D.matplot(xdens$z,c(1,0),c(0,1),c(0,0),
show.legend=TRUE,xlab="Columns",ylab="Rows")

Jim

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html