[R-sig-Geo] Legend in density plot

Rolf Turner r.turner at auckland.ac.nz
Sat Nov 19 00:43:49 CET 2011


On 18/11/11 21:13, Albin Blaschka wrote:
>
>
> Dear list!
>
> I have GPS data for three seasons of roaming livestock and to get an 
> idea which areas the animals occupied and the differences between the 
> seasons, I am plotting density plots for each season like this:
>
> posi <- readOGR(dsn = "PG:host=127.0.0.1 user=user dbname=mydb 
> password=secret, layer = "mylayer")
>
> pposi <- ppp(posi at coords[,1], 
> posi at coords[,2],xrange=c(posi at bbox[1,1],posi at bbox[1,2]), 
> yrange=c(posi at bbox[2,1],posi at bbox[2,2]))
>
> densi <- density(pposi, bw = "nrd0", adjust = 0.1, kernel = 
> c("epanechnikov"), edge = TRUE, diggle=TRUE)
>
> plot(densi, col = mypalette)
>
> so far, so good:
>
> BUT as there where differences between the years, the legend which is 
> plotted on the left of each map shows different values/ has different 
> ranges, which is bad for a comparision, so my question is:
>
> How can I change the range and the ticks in the legend of a density map?
>
> I hope I made my point clear - Thank you in advance!

I ***think*** when you say ``legend'' you mean the ***ribbon*** that 
appears at
the right hand side of an "im" plot.  And I ***think*** you want this 
ribbon to cover
the same range of values for each plot.

This is easily done --- choose the range of values that you want to use, 
and invoke
the argument "zlim".

Here's a toy example:

X <- im(matrix(runif(10000),100,100))
Y <- im(matrix(runif(10000,0.5,1.5),100,100))
plot(X) # No adjustment --- the two images look pretty much the same;
plot(Y) # you can't see the difference in the ranges of values.

plot(X,zlim=c(0,1.5))
plot(Y,zlim=c(0,1.5)) # Now the difference is obvious.

I hope I have interpreted your question correctly.  If not, please let me
know, with clarifications.

     cheers,

         Rolf Turner



More information about the R-sig-Geo mailing list