I am using mgcv with factor smooths to compare smooths of 5 Type factors. Example code is m <- gamm(Y ~ s(X,Type, bs="fs"),random=list(UnID=~1) I plot the results using plot(m) but how do I link the different colours plotted to the factors. Essentially I need to produce a legend but cannot work out how to do this.
Asked
Active
Viewed 222 times
1
plot()method that mgcv provides. You can either take the data from the object returned by theplotmethod (i.e. infoofromfoo <- plot(m)), or use my gratia package and dofoo <- evaluate_smooth(m)and then use ggplot2 (there'll be a variableTypeinfoothat you can use for the colour aesthetic). You'll need to ask further Q's on [so] or in the Issues on the github site for gratia if something isn't clear or doesn't work. – Gavin Simpson Jan 11 '19 at 17:07