I am trying to make a trajectory line representing brain atrophy over time. I have two specific trajectories for two different groups, and I want to add each of these two lines (for comparison) to a scatterplot of Age by Brain Volume.
The y-intercepts of these lines are 565 and 286, yet using the stat_function layer it seems to be placing the intercepts at very weird values, corrupting the overall scatterplot. Of course I can use ylim(), but then the functions don't appear (and they'd still be mis-specified even if they did).
My code:
ggplot(na.omit(GRAPHICSMATRIX), aes(x=Age, y=FrontalPole, colour=Dx_Bl)) +
geom_point(size=3) +
ylim(0, 500) +
stat_function(fun=function(x) {-2.129*x^3 - 23.456*x + 565}, colour="blue", size=1) +
stat_function(fun=function(x) (286)+((-0.997)*(x)^3), colour="darkred", size=2)
Here are the graphs.


function(x) {-2.129*x^3 - 23.456*x + 565}withGRAPHICSMATRIX$Ageas input outside of the ggplot2 code?x=0. Your plots start aroundx=60in which case you function gives a result on the order of 216,000. Just plug inx=60and you can see that.