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

Claudia Beleites cbeleites at units.it
Mon Feb 28 15:46:44 CET 2011


Pierz,

- easy approximation: use coulours with alpha value for plotting points
 > x <- runif (1000)
 > y <- runif (1000) * x + x
 > plot (x, y)
 > plot (x, y, pch = 20, col = "#FF000020")

- more sophisticated:
  have a look at hexbin (package hexbin), levelplot (package lattice), package 
ggplot2 with stat_sum, stat_binhex, or stat_density2d (e.g. 
http://had.co.nz/ggplot2/stat_sum.html)

HTH Claudia

On 02/28/2011 03:21 PM, pierz wrote:
> 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:
> http://r.789695.n4.nabble.com/file/n3327986/example_R.jpg
>
> This is the result I am aiming for:
> http://r.789695.n4.nabble.com/file/n3327986/example_matlab.jpg
>
>


-- 
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbeleites at units.it



More information about the R-help mailing list