[R] vis.gam() contour plots

Jason Gasper Jason.Gasper at noaa.gov
Tue Oct 13 22:37:24 CEST 2009


Thanks, that is a big help.

David Winsemius wrote:
>
> On Oct 13, 2009, at 3:46 PM, Gavin Simpson wrote:
>
>> On Mon, 2009-10-12 at 22:20 -0400, David Winsemius wrote:
>>> On Oct 12, 2009, at 8:20 PM, Jason Gasper wrote:
>> <snip />
>>> # contour examples.... vis.gam(g,
>>> view=c("x1","x2"),plot.type="contour",color="heat", nlevels=20)
>>> Warning messages:
>>> 1: In plot.window(...) : "nlevels" is not a graphical parameter
>>> 2: In plot.xy(xy, type, ...) : "nlevels" is not a graphical parameter
>>> 3: In axis(side = side, at = at, labels = labels, ...) :
>>>   "nlevels" is not a graphical parameter
>>> 4: In axis(side = side, at = at, labels = labels, ...) :
>>>   "nlevels" is not a graphical parameter
>>> 5: In box(...) : "nlevels" is not a graphical parameter
>>> 6: In title(...) : "nlevels" is not a graphical parameter
>>>
>>> # This does result in warnings that do not seem correct (since nlevels
>>> is listed as a graphics parameter in the help page of contour)
>>
>> They are correct for a certain definition of "graphical parameter", and
>> 'nlevels' is an argument to contour. IIRC this really refers to things
>> in ?par and is a common issue that I have come across when coding
>> function that pass some arguments in '...' to other functions and some
>> to plotting functions. There are ways around this, but I don't have the
>> details to hand - Prof. Ripley suggested one solution that is used
>> within base R to get round this problem, and which we subsequently used
>> in the vegan package.
>
> This the case. Looking at the code it appears the vis.gam function may 
> have been written with the persp plotting case in mind. There is some 
> minimal processing of parameters when the call is for "contour", and 
> nlevels is not a named argument within vis.gam. If you make it one, 
> and then pass it to the contour call within the eval(parse(text= )) 
> dispatching strategy, you can avoid the warnings:
>
> vis.gam2(g, view=c("x1","x2"),plot.type="contour",color="heat", 
> nlevels=20)
> #no warnings
>
> #after defining the function
> vis.gam2 <- function (x, view = NULL, cond = list(), n.grid = 30, 
> too.far = 0,
>     col = NA, color = "heat", contour.col = NULL, se = -1, type = 
> "link", nlevels=10,
>     plot.type = "persp", zlim = NULL, nCol = 50, ...)
> {
>     ---snipped unchanged code-----
>         if (plot.type == "contour") {
>             stub <- paste(ifelse("xlab" %in% dnm, "", ",xlab=view[1]"),
>                 ifelse("ylab" %in% dnm, "", ",ylab=view[2]"),
>                 ifelse("main" %in% dnm, "", ",main=zlab"), ",...)",
>                 sep = "")
>             if (color != "bw") {
>                 txt <- paste("image(m1,m2,z,col=pal,zlim=c(min.z,max.z)",
>                   stub, sep = "")
>                 eval(parse(text = txt))
>                 txt <- 
> paste("contour(m1,m2,z,col=contour.col,zlim=c(min.z,max.z)",
>                   ifelse("add" %in% dnm, "", ",add=TRUE"), ", nlevels= 
> nlevels, ...)",
>                   sep = "")
>                 eval(parse(text = txt))
>             }
>             else {
>                 txt <- paste("contour(m1,m2,z,col=1,zlim=c(min.z,max.z)",
>                   stub, sep = "")
>                 eval(parse(text = txt))
>             }
>         }
> ---snipped more unchanged code-------
> }
>
>>
>> HTH
>>
>> G
>>
>>> but the
>>> desired effect seems to be occurring. I have seen such warnings many
>>> times before an have learned to ignore them. Whether that is the
>>> correct posture to assume, I am not sure.
>>>> Thanks
>>>
>>> -- 
>>>
>>> David Winsemius, MD
>>> Heritage Laboratories
>>> West Hartford, CT
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide 
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> -- 
>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>> Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
>> ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>> Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
>> Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
>> UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>

-- 
Jason Gasper
National Marine Fisheries Service
Alaska Region, Sustainable Fisheries Division
709 W. 9th St. Juneau, Alaska 99801 
Juneau, Alaska 99801

Phone  907-586-7237
Fax 907-586-7249




More information about the R-help mailing list