I'm using ggplot
to generate a scatter plot with a fitted line as follows
ggplot(df, aes(x=colNameX, y=colNameY)) +
geom_point() +
geom_smooth(method=loess, se=T, fullrange=F, size=1) + ylim(0,5)
Given this, want to generalize above into a function that takes the following arguments
scatterWithRegLine = function(df, xColName, yColName, regMethod, showSe, showFullrange, size, yAxisLim) {
# How should I use the variables passed into the function above within ggplot
}
Such that I can call the function as follows
scatterWithRegLine(df, "mpg", "wt", "loess", TRUE, FALSE, 1, c(0,5))