[R] How to plot a image with restrictions?

Roger Bivand Roger.Bivand at nhh.no
Thu Jun 22 09:56:28 CEST 2006


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:

http://finzi.psych.upenn.edu/R/Rhelp02a.new/archive/15030.html

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

> 
> Thanks in advance!
> 
> 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 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
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-help mailing list