Plotting a GAM contour plot with the response scale in tidymv

Viewed 34

I have created a GAM using the mgcv package with the gamma family. I then plot it with tidymv so that I use ggplot2. However, it plots the transformed values for the scale. How do I plot it in the response scale (0-1 in this case)?

Edited to add sample data and specified k=2 in the example code so it will still run on the sample data.

sourceLambda = c(0.0, 0.1, 0.2, 0.0, 0.1, 0.2, 0.0, 0.1, 0.2)
traitLambda = c(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.2, 0.2, 0.2)
meanT = c(1.052590e-04, 1.588049e-04, 9.678802e-05, 1.090665e-04, 1.265542e-04, 8.495936e-05, 1.399897e-04, 2.928686e-04, 2.481759e-04)
sdata = data.frame(sourceLambda, traitLambda, meanT)

library(tidymv)
library(dplyr)
library(viridis)

x= gam(meanT ~ s(sourceLambda, k=2)+s(traitLambda,k=2), data=cats1,Gamma)
x2 <- predict_gam(x)

x2 %>%
  ggplot(aes(sourceLambda, traitLambda, z = fit)) +
  geom_raster(aes(fill = fit)) +
  geom_contour(colour = "white") +
  theme_bw()+
  scale_fill_viridis("T1", option = "A")

Example plot

0 Answers
Related