[R] modify rectangle color from image

2007-01-24 Thread Saurav Pathak
Hi,

I need some suggestion on how I could modify the color on some
rectangle that I have created using image.

In other words, I have a 5x5 matrix, say, m.  

m - matrix(rnorm(25), nrow=5)

I create a grid of rectangles by:

image(m)

Now I want to change the color of rectangle (3,3) to blue. 

I don't know how this could be done, and searching the web has given
me no hint.  

Thanks for your help.

-- 
saurav

__
R-help@stat.math.ethz.ch 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] modify rectangle color from image

2007-01-24 Thread Saurav Pathak

Thanks,
Saurav


Saurav Pathak [Wed, Jan 24, 2007 at 04:37:20PM -0500]:

+  Hi,
+  
+  I need some suggestion on how I could modify the color on some
+  rectangle that I have created using image.
+  
+  In other words, I have a 5x5 matrix, say, m.  
+  
+  m - matrix(rnorm(25), nrow=5)
+  
+  I create a grid of rectangles by:
+  
+  image(m)
+  
+  Now I want to change the color of rectangle (3,3) to blue. 

using rect for this.

DUH.

-- 
saurav

__
R-help@stat.math.ethz.ch 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] modify rectangle color from image

2007-01-24 Thread Marc Schwartz
On Wed, 2007-01-24 at 16:37 -0500, Saurav Pathak wrote:
 Hi,
 
 I need some suggestion on how I could modify the color on some
 rectangle that I have created using image.
 
 In other words, I have a 5x5 matrix, say, m.  
 
 m - matrix(rnorm(25), nrow=5)
 
 I create a grid of rectangles by:
 
 image(m)
 
 Now I want to change the color of rectangle (3,3) to blue. 
 
 I don't know how this could be done, and searching the web has given
 me no hint.  
 
 Thanks for your help.

Try this:

m - matrix(rnorm(25), nrow = 5)
image(m)

# Get the plot region coords
USR - par(usr)

# Calc the length of a side of a square
SIDE - abs(USR[1] - USR[2]) / 5

# Draw the rect using the appropriate offsets
rect(USR[1] + (SIDE * 2), USR[3] + (SIDE * 2), 
 USR[1] + (SIDE * 3), USR[3] + (SIDE * 3), col = blue)


See ?par and review usr, then see ?rect

par(usr) gives you the coordinates of the plot region. Then just do
the math to calculate the coordinates of each rectangle.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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.