[R] re-arranging data to create an image (or heatmap)

From: pierz <s.piersma_at_gmail.com>
Date: Mon, 28 Feb 2011 06:21:44 -0800 (PST)

Let me start by introducing myself as a biologist with only a little knowledge about programming in matlab and R. In the past I have succesfully created my figures in matlab using the hist3d command, but I have not access to matlab right now and would like to switch to R.

I have used the plot command to create a figure of my data and it does almost what I want it to do.

My data matrix looks like this (these are the first few lines from it, copied from R console):

         Time Abs
   [1,]  0.09714286                24
   [2,]  0.19428571                24
   [3,]  0.19428571                24
   [4,]  0.29142857                24
   [5,]  0.38857143                23
   [6,]  0.38857143                22
   [7,]  0.48571429                23
   [8,]  0.58285714                21
   [9,]  0.58285714                21

[10,] 0.68000000 23
[11,] 0.68000000 25
[12,] 0.68000000 23
[13,] 0.77714286 23
[14,] 0.77714286 23
[15,] 0.87428571 21
[16,] 0.87428571 20
[17,] 0.87428571 22
[18,] 1.06857143 23
[19,] 1.06857143 25

The example shows that some of the plotted points appear more than once. I would like to use a heatmap to show that these points have more weight, but I have difficulty arranging the data to be plotted correctly using the image() or heatmap() command.

So what I would want to do is to get the same figure as when I use the plot command, but have colors representing the weight of the plotted points (wether they occur once, twice or multiple times).

I have tried searching this forum and also used google, but I seem to keep going in circles. I think that the image() command fits my needs, but that my input data is not in the correct format.

Attached I have an image example from R and an image example from matlab. This is how far I got using R:

This is the result I am aiming for:

View this message in context: http://r.789695.n4.nabble.com/re-arranging-data-to-create-an-image-or-heatmap-tp3327986p3327986.html
Sent from the R help mailing list archive at Nabble.com.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 28 Feb 2011 - 14:31:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Feb 2011 - 15:10:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive