# Re: [R] How to plot a image with restrictions?

From: Roger Bivand <Roger.Bivand_at_nhh.no>
Date: Thu 22 Jun 2006 - 17:56:28 EST

On Wed, 21 Jun 2006, Cleber N.Borges wrote:

>
>
> Hello All!
>
>
> How to plot a image ( image function )
> with restrictions, like a polygon??

The suggestions given in:

by Denis White let you overplot the image with a masking polygon - that may be the most suitable for you. Alternatively, you can set the image values to be omitted to NA, but how you would do this depends rather on whether the polygon is irregular or not. If the polygon is regular, unrolling the image into a vector and setting conditions on expand.grid() of the row and column coordinates will work with is.na(). If irregular, you'll need to do point-in-polygon checking of the image grid coordinates. If your data are geographical (not assumed here), you may like to follow this up on the R-sig-geo list.

Roger

>
>
> Cleber N. Borges
>
>
> ##### problem example
>
> x <- y <- seq(-4*pi, 4*pi, len=27)
> r <- sqrt(outer(x^2, y^2, "+"))
> image( z )
> contour(z, add = TRUE, drawlabels = FALSE)
>
> m=scan()
> 0.2 0.2
> 0.8 0.2
> 0.5 0.8
>
> m = matrix(m,nr=3,byrow=T)
> polygon( m, lwd=5 )
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
>

```--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand@nhh.no

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help