If you still receive this message, you need to update mgcv and gam package to the latest version. A big change was made for the gam package in February 2018: Could not find the plot.gam function . This means that the GAM installed by the gam package now has the "Gam" class, and even if the mgcv package mgcv loaded, plot will not select mgcv::plot.gam to build it.
However, it is still unsafe to have both packages in an R session. Therefore, the next proposal made in 2016 is still highly recommended.
Sentence
It would be nice to have this toy feature to check if the R session is ok to start the GAM analysis.
GAM_status <- function () { if (all(c("gam", "mgcv") %in% .packages())) print("Not OK") else print("OK") }
nsdf is a strict freedom number , a term used exclusively in mgcv . As you mentioned: mgcv is the plot.gam function.
The problem is that you have gam and mgcv , two incompatible packages in your R session at the same time. You fit your gam.mod with gam::gam , but then build the model with mgcv::plot.gam .
Note that what is usually true when using :: will lose effect here. Usually, when two packages have some functions between masks, the :: means is a means of protection. But, for mgcv and gam , this is completely impossible. Therefore, I suggest that if you use gam , never touch mgcv in your R session, and vice versa.
So, I am starting a new R session and doing the following, everything is in order!
library(gam) library(ISLR)

Thanks for your reply. I never downloaded mgcv , I just assumed this was a gam . I started a new R session and the code you provided worked. I found that this car library is actually causing the same problem.
mgcv and gam are independent of each other, but since mgcv is more popular than gam , many packages are dependent on mgcv , for example, car :
car: Companion to Applied Regression Functions and Datasets to Accompany J. Fox and S. Weisberg, An R Companion to Applied Regression, Second Edition, Sage, 2011. Version: 2.1-3 Depends: R (≥ 3.2.0) Imports: MASS, mgcv, nnet, pbkrtest (≥ 0.4-4), quantreg, grDevices, utils, stats, graphics
Note that in the Import field, the library(car) will load these packages at the same time.