1

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()
  • To get answers, it is best to simplify the code you include to the bare minimum needed to demostrate the problem. Make the code a "reprex", in other words code that can be run as is. Most likely you will have to right a "toy example" with the bare minimum of data, either data available in R or generated by the code. A simple and small data set. In this way those who could answer can provide working code in their answers. – Pedro J. Aphalo Sep 06 '22 at 17:47
  • 1
    Anyway, there is no way to use a ggplot statisitc to set a subtitle. There are two possible ways around: 1) fit the model outside of the ggplot code and manually set the subtitle to an expression (see `help(plotmath)` for the syntax) or 2) disable clipping at the edge of the plotting area by adding to the plot code `+ coord_cartesian(clip = "off")` and use a satistic to add the equation but giving coordinates corresponting to the marging. – Pedro J. Aphalo Sep 06 '22 at 17:52

0 Answers0