[R] question on contour function

Duncan Murdoch murdoch.duncan at gmail.com
Thu Aug 12 02:37:56 CEST 2010

On 11/08/2010 11:16 AM, ba ba wrote:
> Dear All,
> I tried to plot contour lines using R function contour, but got the results
> which are not expected.
> require(RTOMO)
> x <- seq(-1,1,0.1)
> y <- seq(-1,1,0.1)
> xy <- meshgrid(x,y)
> z <- xy$x^2+ 3*xy$y^2
> contour(x,y,z,col="blue",xlab="x",ylab="y")
> The above code gave me the contour graph for z=3*x^2+y^2 rather than
> z=x^2+3*y^2. Is anyone know the reason? Thank you very much in advance.

A problem in RTOMO, or a misuse of it?  If I do the calculation of z as

z <- outer(x, y, function(x,y) x^2+3*y^2)

I get the expected result.

Duncan Murdoch

More information about the R-help mailing list