'X and Y label in self-build function in R not working for plotting
This is my code:
gam.model <- function(df, outcome, exposure){
#linear model (using gam function)
mod.lm <- gam(outcome ~ exposure + GENDER, data = df)
#gam model with non linear term
mod.gam <- gam(outcome ~ s(exposure) + GENDER, data = df)
#results from the gam model
print(summary(mod.gam))
plot(mod.gam, xlab = exposure, ylab = outcome)
#compare linear and non linear models
anova.gam(mod.lm,mod.gam,test="Chisq")
}
I want to create a function where I put in a dataframe, a list of outcomes and a list of exposures. And in that function I want to run GAM-models and plot them. However, I dont know what i should put behind x-lab and y-lab for the function to plot the correct name of the variabel on the x- and y-axis.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
