[R] about image() function in R and colors

From: Mikkel Grum <mi2kelgrum_at_yahoo.com>
Date: Fri 08 Jul 2005 - 19:01:50 EST


Javier, on the image and colors, did you try using the breaks option? You will need 21 breaks to display 20 colors (see ?image).

Janek, the option asp = 1 should generally solve your scaling problem (point 2 below). I don't remember where I got that from, but it works unless you use functions like abline which will take up the whole plot region. Then you can adjust the plot region using

pin = c(diff(range(a*x)), diff(range(a*y)))

see ?par

Best wishes,
Mikkel

R] about image() function in R and colors Tuszynski, Jaroslaw W. JAROSLAW.W.TUSZYNSKI at saic.com
Thu Jul 7 14:22:27 CEST 2005

I do not know the solution to your problem, but I had the similar problems
with image() function and most of derived functions. It seems that 'image'
function was really not meant for displaying image data, instead it was
designed to display matrices in the image format. Matlab had the same
problem and ended up creating 2 functions: 'image' (similar to R's 'image')
and 'imshow' (designed for displaying image data).

There are three major processing steps in the 'image' that are hard to
control or reverse:
1) scaling of the data intensities ( problem explained by Javier). Scaling
is not much of a problem if continuous palette of colors is used , or to
quote
"?image" when "'col' is a list of colors such as that generated by
'rainbow', 'heat.colors', 'topo.colors', 'terrain.colors' or similar
functions". However scaling causes problems in case of discontinuous
color-maps (palettes).
2) scaling of the data dimensions so it fits in default size window instead
of scaling of the window to fit the data. This results in image with
non-square pixels. There might be a way to force 'image' not to scale
dimensions, I just did not spend much time looking for it yet.
3) Flipping of the image. As "?image" shows one needs to "transpose and flip
matrix horizontally" or perform
"image(t(volcano)[ncol(volcano):1,])" for the image data to be visualized in proper orientation.

All those steps make sense in case of visualizing 2D data, but they are a
hindrance in case of visualizing images.

Jarek

====================================================\=======

 Jarek Tuszynski, PhD.                           o / \

 Science Applications International Corporation <\__,|

 (703) 676-4192                                   ">  
\
 Jaroslaw.W.Tuszynski at saic.com                    
` \  

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of javier garcia
Sent: Thursday, July 07, 2005 7:23 AM
To: R-Help
Cc: statsgrass at grass.itc.it
Subject: [R] about image() function in R and colors

Hi!

I've got a map in R imported from a GIS (GRASS) as a vector of factors.
So I've got 20 different levels in the map and I've created a vector of
custom colors of exactly 20 colors in lenght. I'm trying to use image() (really plot.grassmeta() that call image()) to
plot the map with those colors but it doesnt work and the colors are
changed.

I would like that all points belonging to level1 are color 1 , and so on...

Please could you tell me if this procedure is not correct?

Best regards,

Javier

--
A. Javier Garcia
Water and Soil conservation department
CEBAS-CSIC
Campus Universitario Espinardo
PO BOX 164
30100 Murcia (SPAIN)
Phone: +34 968 39 62 57
Fax: +34 968 39 62 13
email: rn001 at cebas.csic.es

______________________________________________
R-help at 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


* Previous message: [R] Tables: Invitation to make
a collective package
* Next message: [R] Kernlab: problem with small
datasets
* Messages sorted by: [ date ] [ thread ] [
subject ] [ author ] __________________________________ Stay connected, organized, and protected. Take the tour: ______________________________________________ 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
Received on Fri Jul 08 19:06:31 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:22 EST