Q: Error when running Spline curve through ggplot 2 I created a spline plot using RMS and want to tidy it up, similar to how it was done in this example http://rstudio-pubs-static.s3.amazonaws.com/256256_c8c334094db34575a9bbfdd2b686c019.html
However While I am able to create a spline plot (see below), when I try to pass it through ggplot using the same code as the link above, I get this error Error: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class trellis. I am not sure what to do, as this is exactly what was done .in the above example, and dataplot cannot be coerced into a dataframe as it is a trellis. Why am I getting this error and how can I remedy this?
ddist <- datadist(df)
options(datadist='ddist')

k <- with(df, quantile(X, c(.05, 0.25, 0.50, .75, .95)))

spline_model <- lrm(Y ~ rcs(X, k), data=df)   ###could add + other variables after ...k)

dataplot <- plot(Predict(spline_model, BMI_NUM, ref.zero=TRUE, fun=exp))

ggplot(dataplot, aes(BMI_NUM, yhat)) +    #####ERROR OCCURS AT THIS LINE
  #  geom_line(colour="Black", linetype="dashed", size=1.5)+
  theme(plot.subtitle = element_text(vjust = 1),
        plot.caption = element_text(vjust = 1),
        axis.line = element_line(size = 0.5,
                                 linetype = "solid"), panel.grid.major = element_line(colour = "gray98"),
        axis.title = element_text(size = 15),
        panel.background = element_rect(fill = "gray99",
                                        colour = "white", linetype = "twodash"),
        plot.background = element_rect(fill = "white")) +
  scale_x_continuous(breaks = seq(15,50,by=2.5),expression(paste("Body Mass Index", ", ", kg/m^{2})))+
  scale_y_continuous(limits = c(0,10), breaks = seq(0,10,by=0.5),"Odds Ratios (95%CI)")+
  labs(caption = NULL)+
  annotate("text", x=20, y=9, parse = TRUE,
           label="Women",
           size=5)+
  geom_hline(yintercept =1, linetype="dashed")


For reference, when I just run dataplot, I do get a nice spline curve, so that is not where the issue lies.


A: I just figured it out. I had dataplot <- plot(Predict(spline_model, BMI_NUM, ref.zero=TRUE, fun=exp)), but it was supposed to be dataplot <- Predict(spline_model, BMI_NUM, ref.zero=TRUE, fun=exp)
