1

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.

  • Hi Geoff! This is a programming question (hence closed as OT here). There isn't a way with the plot() method that mgcv provides. You can either take the data from the object returned by the plot method (i.e. in foo from foo <- plot(m)), or use my gratia package and do foo <- evaluate_smooth(m) and then use ggplot2 (there'll be a variable Type in foo that 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

0 Answers0