[R-sig-Geo] raster package display

Colin Robertson colinr23 at gmail.com
Wed Jun 29 18:21:11 CEST 2011


Thanks Barry, that was it.

Colin

On Wed, Jun 29, 2011 at 12:13 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> On Wed, Jun 29, 2011 at 4:50 PM, Colin Robertson <colinr23 at gmail.com> wrote:
>> Dear List,
>>
>> I am creating a raster as the output of a function, and for testing
>> purposes the output of this function should be a raster with all 1's.
>>
>> When I check with summary, this is the case:
>>
>> class(out[[2]])
>> [1] "RasterLayer"
>> attr(,"package")
>> [1] "raster"
>>
>> summary(out[[2]])
>> Cells:  1600
>> NAs  :  304
>>
>> Min.      1
>> 1st Qu.   1
>> Median    1
>> Mean      1
>> 3rd Qu.   1
>> Max.      1
>> NA's    304
>>
>> Yet when I plot using plot(out[[2]]), I get a display of values
>> ranging from 0.6 - 1.4.
>>
>> All summaries on the raster indicates all cells have value of 1, but
>> the display shows differently.
>>
>> Any ideas on what is happening here much appreciated,
>
>  I suspect - and a quick look at the code will confirm it - that it
> just decides to expand the key a bit because your values are all 1.
>
>  The image.plot function in the fields package does the same thing for
> a matrix of all the same values.
>
>  In a way it's not lying, because its showing you all the cells with
> value 1 are the same colour. It's just not showing you that there are
> no cells with any other colour. I guess a scale with 1 at the top,
> middle, and bottom would look odd.
>
>  If you add a zlim parameter you can get something that may be a bit
> more meaningful:
>
>  m=raster(matrix(1,10,10))
>  plot(m)
>  plot(m,zlim=c(0.99,1.01))
>
>  - the colour ramp then shows you there's nothing at 1.010, since
> there's nothing green on the plot...
>
> Barry
>



More information about the R-sig-Geo mailing list