[R] Frequencies from x/y data into a 2d table (for 3d histogram or heatmap)

David L Carlson dcarlson at tamu.edu
Wed Feb 29 21:34:43 CET 2012


Something like this?

x <- round(runif(100, 0, 40), 0)
y <- round(runif(100, 0, 40), 0)
xgroup <- cut(x, seq(0, 40, 10), include.lowest=TRUE)
ygroup <- cut(y, seq(0, 40, 10), include.lowest=TRUE)
xy <- table(xgroup, ygroup)
image(xy)

You'll still have to work with the plot commands to label it properly.

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Marcio Pupin Mello
Sent: Wednesday, February 29, 2012 12:49 PM
To: r-help at stat.math.ethz.ch
Subject: Re: [R] Frequencies from x/y data into a 2d table (for 3d histogram
or heatmap)

Hi Ralf,
have you solved your problem?! If so, could you share? I have the same 
problem...
Best,

Marcio


On 3/25/10 6:03 PM, Ralf B wrote:
> Hi all,
>
> I have simple x/y data from screen recording in a sequence:
>
> number,x,y
> ----------------
> 1,10,30
> 1,20,
> 1,43,110
> 1,74,18
> 1,88,112
>
> and would like to create a 3d histogram data structure that i can use
> to create a 3d histogram or, more likely a heatmap. The unterlying
> data structure therefore needs to look like this:
>
>            0-10        11-20         21-30        31-40
> 0-10
> 11-20
> 21-30
> 31-40
>
> where the values in the cells represent counts of datapoints fitting
> respective ranges for x and y. Can somebody point me to a procedure in
> R that can make such a transformation for different range sizes (i.e.
> 10 in my example)? I came across the following method:
>
>
https://stat.ethz.ch/pipermail/r-help/attachments/20070425/fcb92205/attachme
nt.pl
>
>
> which seems (at least close) but did not get it running (could not
> find clear3d()). I also dont' need the 3d histogram plot as I will be
> using the table to create a heatmap. I might be thinking to
> complicated here. To me, it seems like this should be possible with a
> few lines of code. Perhaps one of you has them lying around somewhere
> or knows a script that does the trick.
>
> Thanks in advance!
>
> Ralf
>

______________________________________________
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