Display line equation in subtitle of ggplot?

137 views Asked by At

Below is the code for creating bulk hydrographs from a formatted .csv file in a network drive. stat_regline_equation(data=cont, aes(x,y)) allows me to print the continuous data line equation on the plot, but I was hoping I could add it to the subtitle instead. Is this possible?

I would attach the full code but stack won't let me submit so much code without more question details. If you would like to see the full code, just ask in a comment. This paragraph serves to create more lines of detail than lines of code.

details

  #plot continous data
  p <- ggplot() +
    geom_line(data=cont, aes(x,y), color="cyan4", size=0.5) +
    geom_point(data=disc, aes(x,y), color="gray22",shape=8,size=1.5,stroke=0.7) +
    geom_smooth(data=cont, aes(x,y), method=lm, se=FALSE, col='red', size=1) +
    stat_poly_line(data=cont, aes(x,y))+
    stat_regline_equation(data=cont, aes(x,y))+
   ggtitle(paste(station, longName), subtitle=paste("Well depth:", totalDepth, "ft",county))) +
   xlab("Date") + ylab("Depth to water (ft)") + scale_y_reverse() +
   theme(axis.title.x = element_text(color="gray40",face="bold",size=11), axis.title.y=element_text(color="gray40",face="bold",size=11),
   axis.text=element_text(size=12))

print(p)

}

dev.off()
0

There are 0 answers