[R] Plotting a Trivial Matrix

2010-02-26 Thread Lorenzo Isella

Dear All,
Consider a matrix (N x N) where each entry is either zero or one (can
hardly get any simpler).
Now, I would like to plot it as a 'chessboard' where every matrix entry
is a black (1) or white (0) square.
Whatever tool I use to plot it, it should not try to interpolate the
data at all.
I found some online references
http://www.phaget4.org/R/image_matrix.html
but probably I can resort to something much simpler.
Can anyone provide me with a simple example I can modify later on?
Many thanks

Lorenzo

__
R-help@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.


Re: [R] Plotting a Trivial Matrix

2010-02-26 Thread baptiste auguie
Hi,

A minimalist example using Grid graphics,



library(RGraphics)

bwImage - function(m, cols=c(white, black),
draw=TRUE, gp=gpar()){

g - imageGrob(nrow(m), ncol(m),
   cols=cols[m+1], gp=gp)

if(draw)
  grid.draw(g)
return(g)
}

m - matrix(rnorm(200)  0,  ncol=20)
bwImage(m)

HTH,

baptiste

On 26 February 2010 09:29, Lorenzo Isella lorenzo.ise...@gmail.com wrote:
 Dear All,
 Consider a matrix (N x N) where each entry is either zero or one (can
 hardly get any simpler).
 Now, I would like to plot it as a 'chessboard' where every matrix entry
 is a black (1) or white (0) square.
 Whatever tool I use to plot it, it should not try to interpolate the
 data at all.
 I found some online references
 http://www.phaget4.org/R/image_matrix.html
 but probably I can resort to something much simpler.
 Can anyone provide me with a simple example I can modify later on?
 Many thanks

 Lorenzo

 __
 R-help@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.




-- 


Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
R-help@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.


Re: [R] Plotting a Trivial Matrix

2010-02-26 Thread Jim Lemon

On 02/26/2010 07:29 PM, Lorenzo Isella wrote:

Dear All,
Consider a matrix (N x N) where each entry is either zero or one (can
hardly get any simpler).
Now, I would like to plot it as a 'chessboard' where every matrix entry
is a black (1) or white (0) square.
Whatever tool I use to plot it, it should not try to interpolate the
data at all.
I found some online references
http://www.phaget4.org/R/image_matrix.html
but probably I can resort to something much simpler.
Can anyone provide me with a simple example I can modify later on?


Hi Lorenzo,

trivial_matrix-matrix(sample(0:1,100,TRUE),nrow=10)
require(plotrix)
color2D.matplot(trivial_matrix,main=A trivial Plot)

Jim

__
R-help@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.


Re: [R] Plotting a Trivial Matrix

2010-02-26 Thread Lorenzo Isella

baptiste auguie wrote:

Hi,

A minimalist example using Grid graphics,



library(RGraphics)

bwImage - function(m, cols=c(white, black),
draw=TRUE, gp=gpar()){

g - imageGrob(nrow(m), ncol(m),
   cols=cols[m+1], gp=gp)

if(draw)
  grid.draw(g)
return(g)
}

m - matrix(rnorm(200)  0,  ncol=20)
bwImage(m)

HTH,

baptiste

On 26 February 2010 09:29, Lorenzo Isella lorenzo.ise...@gmail.com wrote:
  

Dear All,
Consider a matrix (N x N) where each entry is either zero or one (can
hardly get any simpler).
Now, I would like to plot it as a 'chessboard' where every matrix entry
is a black (1) or white (0) square.
Whatever tool I use to plot it, it should not try to interpolate the
data at all.
I found some online references
http://www.phaget4.org/R/image_matrix.html
but probably I can resort to something much simpler.
Can anyone provide me with a simple example I can modify later on?
Many thanks

Lorenzo

__
R-help@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.






  

Thanks Augustine and Jim for the prompt reply.
You both answered my question. To avoid another post, I would simply 
like to know if something along these lines is doable also with ggplot2.

Many thanks

Lorenzo

__
R-help@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.


Re: [R] Plotting a Trivial Matrix

2010-02-26 Thread Tobias.Mathow
What about 

http://www.phaget4.org/R/image_matrix.html

try function f.matrix.plot



Tobias Mathow
Forest Research Institute Baden-Wuerttemberg (FVA) 
Wonnhaldestr. 4, D- 79100 Freiburg 
Phone: ++49-761-4018-365
www.fva-bw.de


-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im 
Auftrag von Lorenzo Isella
Gesendet: Freitag, 26. Februar 2010 09:30
An: r-help
Betreff: [R] Plotting a Trivial Matrix

Dear All,
Consider a matrix (N x N) where each entry is either zero or one (can
hardly get any simpler).
Now, I would like to plot it as a 'chessboard' where every matrix entry
is a black (1) or white (0) square.
Whatever tool I use to plot it, it should not try to interpolate the
data at all.
I found some online references
http://www.phaget4.org/R/image_matrix.html
but probably I can resort to something much simpler.
Can anyone provide me with a simple example I can modify later on?
Many thanks

Lorenzo

__
R-help@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.

__
R-help@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.


Re: [R] Plotting a Trivial Matrix

2010-02-26 Thread baptiste auguie
On 26 February 2010 11:12, Lorenzo Isella lorenzo.ise...@gmail.com wrote:

 Thanks Augustine and Jim for the prompt reply.
 You both answered my question. To avoid another post, I would simply like to
 know if something along these lines is doable also with ggplot2.
 Many thanks

 Lorenzo


Augustine???

Anyhow, with ggplot2,

m - matrix(rnorm(200)  0,  ncol=20)

require(ggplot2)

d - melt(m)
qplot(X1, X2, data=d, fill=value, geom=tile) +
  scale_fill_manual(values=c(white, black))

HTH,

baptiste

__
R-help@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.