I'm trying to plot some piecewise/broken-stick regressions using geom_smooth. For example:
ggplot(mtcars, aes(x = mpg, y = hp)) + geom_point() + geom_smooth(method = lm, formula = y ~ splines::bs(x, df = 2, degree = 1, knots = 20)) + facet_wrap(~gear)
However this uses a single value (knots=20) for the breakpoint in each facet. I would like to pass a unique value for each facet (that I have calculated earlier). Is this possible?
I tried adding a variable to the data frame and passing the variable name (e..g,
psi) as an aesthetic, but geom_smooth wouldn't recognize it. I suspect the answer has something to do with defining a custom function as described at the end of this page: https://ggplot2.tidyverse.org/reference/geom_smooth.html
Thanks so much for this package - it is amazing and I love using it.