0

I am running a GAMM using package mgcv. The model is running fine and gives an output that makes sense, but when I use vis.gam(plot.type="persp") my graph appears like this: enter image description here

Why is this happening? When I use vis.gam(plot.type="contour") there is no area which is transparent.

It appears to not simply be a problem with the heat color pallete; the same thing happens when I change the color scheme of the "persp" plot: persp plot, "topo" colour

The contour plot is completely filled while the persp plot is still transparent at the top. Data:

      logcpue assnage distkm fsamplingyr
1  -1.5218399       7  3.490        2015
2  -1.6863990       4  3.490        2012
3  -1.4534337       6  3.490        2014
4  -1.5207723       5  3.490        2013
5  -2.4061258       2  3.490        2010
6  -2.5427262       3  3.490        2011
7  -1.6177367       3  3.313        1998
8  -4.4067192      10  3.313        2005
9  -4.3438054      11  3.313        2006
10 -2.8834031       7  3.313        2002
11 -2.3182512       2  3.313        1997
12 -4.1108738       1  3.235        2010
13 -2.0149030       3  3.235        2012
14 -1.4900912       6  3.235        2015
15 -3.7954892       2  3.235        2011
16 -1.6499840       4  3.235        2013
17 -1.9924302       5  3.235        2014
18 -1.2122716       4  3.189        1998
19 -0.6675703       3  3.189        1997
20 -4.7957905       7  3.106        1998
21 -3.8763958       6  3.106        1997
22 -1.2205021       4  3.073        2010
23 -1.9262374       7  3.073        2013
24 -3.3463891       9  3.073        2015
25 -1.7805862       2  3.073        2008
26 -3.2451931       8  3.073        2014
27 -1.4441139       5  3.073        2011
28 -1.4395389       6  3.073        2012
29 -1.6357552       4  2.876        2014
30 -1.3449091       5  2.876        2015
31 -2.3782225       3  2.876        2013
32 -4.4886364       1  2.876        2011
33 -2.6026897       2  2.876        2012
34 -3.5765503       1  2.147        2002
35 -4.8040211       9  2.147        2010
36 -1.3993664       5  2.147        2006
37 -1.2712250       4  2.147        2005
38 -1.8495790       7  2.147        2008
39 -2.5073795       1  2.034        2012
40 -2.0654553       4  2.034        2015
41 -3.6309855       2  2.034        2013
42 -2.2643639       3  2.034        2014
43 -2.2643639       6  1.452        2006
44 -3.3900241       8  1.452        2008
45 -4.9628446       2  1.452        2002
46 -2.0088240       5  1.452        2005
47 -3.9186675       1  1.323        2013
48 -4.3438054       2  1.323        2014
49 -3.5695327       3  1.323        2015
50 -1.6986690       7  1.200        2005
51 -3.2451931       8  1.200        2006
52 -0.9024016       4  1.200        2002

library(mgcv)
f1 <- formula(logcpue ~ s(assnage)+distkm)
m1 <- gamm(f1,random = list(fsamplingyr =~ 1),
                 method = "REML", 
                 data =ycsnew)
vis.gam(m1$gam,color="topo",plot.type = "persp",theta=180)
vis.gam(m1$gam,color="heat",plot.type = "persp",theta=180)
vis.gam(m1$gam,view=c("assnage","distkm"),
    plot.type="contour",color="heat",las=1)
vis.gam(m1$gam,view=c("assnage","distkm"),
    plot.type="contour",color="terrain",las=1,contour.col="black")
vermicellion
  • 338
  • 2
  • 14
  • The white area in the second plot corresponds to the "transparent" area in the first plot. Try adding a different 'color' argument. See `?vis.gam` Examples section. – IRTFM Jan 27 '17 at 17:17
  • It appears that it goes deeper than just the color pallete. The contour plot with the "topo" color argument is completely filled when plotted while the persp plot is still transparent at the top. – vermicellion Jan 27 '17 at 17:52
  • With no data there is no mechanism for any of us to examine the problem. If you are happy with guesses then continue to wait for an answer to a problem with no code or data. I predict that no one will answer. If you want more than wild-ass-guesses, then read [MCVE] – IRTFM Jan 27 '17 at 18:49
  • Thank you for your patience. I have updated with data and code – vermicellion Jan 30 '17 at 16:40
  • Please exit R. Then test your code in a clean session. I get: `Error in eval(expr, envir, enclos) : object 'fsamplingyr' not found` – IRTFM Jan 30 '17 at 16:54

1 Answers1

1

The code of vis.gam has this:

            surf.col[surf.col > max.z * 2] <- NA

I am unable to understand what it is doing and it appears to be rather ad_hoc. NA values of colors are generally transparent. If you comment out that line (and assign the environment of the new function as:

environment(vis.gam2) <- environment(vis.gam)

.... you get complete coloring of the surface.

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • This makes sense. So I simply need to override the "NA" as transparent to a color. Thank you! +1 – vermicellion Jan 30 '17 at 20:36
  • I'm sorry. I tried to simply comment out that line and insert "environment(vis.gam2) <- environment(vis.gam)" it does not work. I do not completely understand what "environment" is in R. – vermicellion Jan 30 '17 at 21:20
  • You don't "insert" that environment assignment. You run it at the console _after_ the function definition. And if you redefine the function, you will need to run it again. The environment of a function determines where values and helper functions will be found. (And NEVER , EVER use the phrase "it does not work". It is completely unhelpful in understanding what is going wrong. If you got an error... say so. If the result was not what you expected then describe the result.) – IRTFM Jan 30 '17 at 21:43