Reputation: 1
I would like to display the fitted curve of a GAM that I have run with the data points that went into the GAM, in one plot. I'm able to get R to plot them separately by entering the following code, but would like to display them on one plot together.
NewDay <- gam (INI~s(day), family = gaussian, data = INI_New_Day)
plot(NewDay)
plot(INI_New_Day3$day, INI_New_Day$INI))
I am a novice R user
thanks in advance!
Upvotes: 0
Views: 7436
Reputation: 551
You can also plot the points directly using plot(NewDay, residuals=T,pch=15)
Upvotes: 1
Reputation: 145765
plot
usually makes a brand new plot. If you want to add something to an existing plot, you can use points()
or lines()
(or text()
or whatever function corresponds to what you're adding). For your example, this should work:
NewDay <- gam (INI~s(day), family = gaussian, data = INI_New_Day)
plot(NewDay)
points(INI_New_Day3$day, INI_New_Day$INI))
You can often get away with using plot
and passing argument new = TRUE
, but I've run in to problems when I try to rely on that so I always just call points
or lines
. From ?par
:
new
logical, defaulting to FALSE. If set to TRUE, the next high-level plotting command (actually plot.new) should not clean the frame before drawing as if it were on a new device. It is an error (ignored with a warning) to try to use new = TRUE on a device that does not currently contain a high-level plot.
Upvotes: 3