[R] Repeating grey scale in graph?

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed Feb 16 15:41:16 CET 2005


Sander Oom wrote:

> Thanks Peter!
> 
> Of course I only have (nx-1)(ny-1) facets in a x*y plot!
> 
> The help page line:
> ...
> col     the color(s) of the surface facets. Transparent colours are 
> ignored. This is recycled to the (nx-1)(ny-1) facets.
> ...
> just did not ring a bell.
> 
> In fact, it is still not clear to me why it recycles the ramp even 
> though it has a surplus of colours (grey levels)! Why not just ignore 
> the surplus colours?

Indeed, it ignores them in your case, but since each row of your matrix 
there is one too much this one is moved to the next row, 2 from row two 
to three, 3 from three to four, .... and the last nx+ny-1 are omitted.

Uwe Ligges


> 
> Anyway it works,
> 
> Sander.
> 
> 
> Peter Dalgaard wrote:
> 
>> Sander Oom <slist at oomvanlieshout.net> writes:
>>
>>
>>> Dear R users,
>>>
>>> Could somebody tell me why the grey color ramp is repeated in this
>>> graph, eventhough the ramp values go from 0 to 1? I must be missing
>>> something obvious, but I can not see it!
>>>
>>> z <-
>>> c(0.064329041,0.117243316,0.161565116,0.19923015,0.231642175,0.259835539,0.284571226, 
>>>
>>> 0.038507288,0.094184749,0.140959431,0.180803984,0.215159105,0.245096084,0.271412845, 
>>>
>>> 0.00775022,0.066198255,0.115433207,0.157494219,0.193836765,0.225569076,0.253518629, 
>>>
>>> -0.02820814,0.032958752,0.084661362,0.128946221,0.167320522,0.200892494,0.230504392, 
>>>
>>> -0.07003273,-0.005814512,0.048304039,0.094805358,0.135196637,0.170630435,0.201956395, 
>>>
>>> -0.117878701,-0.050461393,0.005991829,0.054672666,0.097103088,0.134398711,0.167423957) 
>>>
>>>
>>> x <- c(0,1,2,3,4,5)
>>> y <- c(50, 100, 150, 200, 250, 300, 350)
>>> z <- matrix(z, nrow=length(x), ncol=length(y), byrow=TRUE)
>>>
>>> #persp(x, y, z, theta = 30, phi = 30, expand = 0.5,
>>> #  box= TRUE, axes= TRUE, ticktype = "detailed", main="Title of plot")
>>>
>>> hgt <- (z - min(z))/ (max(z) - min(z))
>>> z
>>> hgt
>>> cols <- grey(hgt)
>>> persp(x, y, z, col = cols, theta = 30, phi = 30, expand = 0.5,
>>>   box= TRUE, axes= TRUE, ticktype = "detailed", main="Title of plot")
>>>
>>
>>
>> You have 30 facets and 42 colour values. Try it with
>>
>> cols <- grey(hgt[-1,-1])
>>
>>
>




More information about the R-help mailing list