[R] contour question

Petr Pikal petr.pikal at precheza.cz
Mon Aug 6 10:18:25 CEST 2001


Dear R users

I have some problem with contour() graphics. 

I know it can be used for creating contour plot over rectangular grid.

My data set is measured in polar coordinates (radius, angle) because 
of reaction vessel shape. 

Let say

radius <- c(530, 604, 650, 765, 850, 940, 1015, 1130, 1180, 1260)

and for any radius value I have an angle value set

	angle <- 360 * seq(0,168,4)/340

I have temperatures measured at each angle for all radius values and I 
can simply produce a contour plot

	contour(angle,radius,temp)

in case temp is a matrix with length(angle) rows and length(radius) 
columns, but there are not many people who can easily resolve such 
graphing in polar coordinates. Therefore I hoped I could convert it in 
more convenient rectangular (xy) coordinates.

I can compute xy coordinates for instance by

	radius.vec <- as.numeric(as.vector(gl(10,43,labels=radius)))
	angle.vec <- rep(angle,10)
and
	x_cos(angle.vec*pi/180)*radius.vec
	y_-sin(angle.vec*pi/180)*radius.vec

plotting

	temp.vec_as.vector(as.matrix(temp))
	plot(x, y, type="n")
	text(x, y, temp.vec, cex=.5)

gives a nice set of semicircles which map an inner part of reaction 
vessel temperatures over xy grid. But in that case x and y can not be 
expressed as regular sequence grid suitable for contour plotting (or 
am I wrong?).

I tried to interpolate it by loess

	fit 	<-loess(temp.vec ~ x + y, span = .08, control = 
loess.control("interpolate"))
	daf 	<- expand.grid(x = seq(-1260, 1260 ,20), y = seq(-1260 ,0 
,20))
	ppp 	<- predict(fit, daf)
	ppp.mat <- matrix(ppp, ncol=64)
	contour(seq(-1260, 1260, 20), seq(-1260, 0, 20), ppp.mat, 
nlevels=40, add=T, col=2)

which gave almost what I hoped for but the prediction was computed 
and contours were plotted also outside the outermost semicircle.

I expected that for not "correct" set of xy points (e.g. x = 1250, y = -
1250) predict.loess gives NA prediction and that contours will not be 
drawn outside the outermost semicircle, but obviously I am mistaken.

Please can somebody give me a hint how to keep contours "inside" 
the vessel or inside the intended region?

Thanks in advance. 
Petr Pikal
Precheza a.s.
Nabr.Dr.E.Benese 24
tel: 00420 641 25 2257
     +420 (0)724 008 364
     petr.pikal at precheza.cz
     p.pik at volny.cz

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list