Skip to content

Contour lines not plotting in correct position

5 messages · robin hankin, David Winsemius, Duncan Murdoch +1 more

#
On Oct 24, 2012, at 7:42 PM, Thomas Veltman wrote:

            
It seems unlikely that the contour functions is performing improperly.
num [1:96, 1:96] 0.0035 0.0042 0.00489 0.00559 0.00629 ...

My wild guess (in the absence of any specifics about why you thought this was the wrong answer) is that this is due to the fact that matrix indices in R at 1-based, not 0-based as in other languages common among electrical engineers.

And why is this being posted to the Mac-SIG group, anyway? I see no Mac-specific content.

  
    
#
On 12-10-24 10:42 PM, Thomas Veltman wrote:
You use a different definition for the x in the call to contour, i.e. 
seq(0,1,length.out=(nrow(Electrolyzer))), then you used when you 
computed it, i.e. seq(from=0.05,to=1, by=0.01).

A good practice is to compute the x and y vectors just once, and use the 
outer() function to compute the array.  You may need to use Vectorize() 
to make sure your function works properly in outer().  For example,

Electrolyzer <- outer(etaELEC, FE, function(x, y) 
Ecap(FE=y,etaST=0,etaFC=0,etaELEC=x,etaRP=0.6,etaCOMP=0.95,ENH3=340))

then use etaELEC and FE in the calls to contour.  I would also use 
"add=TRUE" in your calls to contour() if you want those plots overlaid: 
  that will work on any device, not just png():

contour(etaELEC, 
FE,Electrolyzer,axes=FALSE,levels=c(-0.1,0,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1), 
add=TRUE)
contour(etaELEC, 
FE,Electrolyzer,axes=FALSE,levels=c(0.102),col="red",add=TRUE)

Another good practice is to simplify your question as much as possible 
before posting it.  Often you'll discover your own error in the simple 
version, and won't need to post at all.

And finally, as David said, this sort of question should go to R-help, 
not R-sig-mac, unless you think there's something Mac-specific about the 
problem.  But posting a working example is much better than most "first 
posts"; thanks for doing that.

Duncan Murdoch