0

I am trying to display a regression equation with an exponential fit to my data but I can't seem to do so.

Here is my original plot with a linear fit:

resp.pl <- resp.mn %>% ggplot(aes(x = SoilT.mn, y = CO2.flux.mn, color = SiteType)) +
                            geom_smooth(aes(fill = SiteType), method = "lm", se = TRUE) +
                            geom_errorbar(aes(ymin = CO2.flux.mn - CO2.flux.sd, ymax = CO2.flux.mn + CO2.flux.sd)) + 
                            geom_errorbarh(aes(xmin = SoilT.mn - SoilT.sd, xmax = SoilT.mn + SoilT.sd)) +
                            geom_point(size = 2.5) + 
                            theme(axis.text=element_text(size = 20), axis.title=element_text(size=24, face="bold")) + 
                            labs(x = "Soil Temperature Mean (°C)", y = "CO2 Flux Mean (g*m2/hr)") +
                            stat_regline_equation(label.x=c(-12, -12, -12), label.y=c(1.5, 1.35, 1.2)) +
                            stat_cor(aes(label=..rr.label..), label.x=-9.5, label.y=c(1.5, 1.35, 1.2))

Plot

And here is what I tried to do to transform my data:

resp.pl <- resp.mn %>% ggplot(aes(x = SoilT.mn, y = CO2.flux.mn, color = SiteType)) +
                            geom_smooth(aes(fill = SiteType), method = "gam", formula = y ~ s(x, k=3), se = TRUE) +
                            geom_errorbar(aes(ymin = CO2.flux.mn - CO2.flux.sd, ymax = CO2.flux.mn + CO2.flux.sd)) + 
                            geom_errorbarh(aes(xmin = SoilT.mn - SoilT.sd, xmax = SoilT.mn + SoilT.sd)) +
                            geom_point(size = 2.5) + 
                            theme(axis.text=element_text(size = 20), axis.title=element_text(size=24, face="bold")) + 
                            labs(x = "Soil Temperature Mean (°C)", y = "CO2 Flux Mean (g*m2/hr)") +
                            stat_regline_equation(label.x=c(-12, -12, -12), label.y=c(1.5, 1.35, 1.2)) +
                            stat_cor(aes(label=..rr.label..), label.x=-9.5, label.y=c(1.5, 1.35, 1.2))         

Plot 2

I managed to transform my line to better fit my data, but the equations & R values that are displaying on my plot are wrong. How do I go about fixing this? Please help.

KaelenTJ
  • 1
  • 1
  • 1
    I think you're going to have to include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to get a good answer quickly. – Kat Aug 14 '21 at 00:44

0 Answers0