I found the way to add linear regression equation on the graph Add regression line equation and R^2 on graph, but I don't know how to do it with non-linear regression equation? Or could anyone give me the suggestions to analyse the "a" and "b" in the equation?
Here is my data please:
structure(list(Date = structure(c(1510617600, 1511481600, 1520467200,
1522022400, 1528156800, 1529798400, 1530230400, 1530489600, 1530921600,
1531785600, 1532131200, 1532563200, 1533168000, 1536192000, 1536537600,
1540425600, 1540944000, 1541289600, 1541808000, 1542067200, 1543881600,
1545004800, 1545264000, 1545523200, 1548288000, 1552003200, 1552435200,
1558137600, 1558569600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Simulated = c(0.211, 0.29775, 0.21325, 0.23875, 0.2135, 0.236,
0.258, 0.2475, 0.2435, 0.2595, 0.23325, 0.2005, 0.26775,
0.258, 0.22025, 0.1855, 0.233, 0.2225, 0.2535, 0.243, 0.25525,
0.229, 0.31, 0.309, 0.2275, 0.31, 0.27525, 0.31, 0.23225),
Measured = c(0.273, 0.297, 0.244, 0.213071610649744, 0.228296298118039,
0.21311677200277, 0.229871184500008, 0.242, 0.25, 0.258,
0.243, 0.205, 0.288, 0.295, 0.265, 0.222, 0.286, 0.296178290058214,
0.270580086126602, 0.258431821264375, 0.251, 0.257, 0.328075306205261,
0.316, 0.27, 0.337, 0.3, 0.319112634183744, 0.278)), row.names = c(NA,
-29L), class = c("tbl_df", "tbl", "data.frame"))
Here is my code:
library(foreign)
library(ggplot2)
library(dplyr)
library(readxl)
library(scales)
library(ggpmisc)
library("RColorBrewer")
df <- read_excel("C:/Rstudy/HydroGOF/ForI_10_40cm.xlsx")
Sys.setlocale("LC_TIME", "English")
Simulated <- df$Simulated
Measured <- df$Measured
Date <- df$Date
ggplot(df, aes(x=Simulated, y=Measured))+
geom_point() +
geom_smooth(method="nls", formula=y ~ b+a*x^2, method.args=list(start = list(a=1, b=1)), se=FALSE)+
scale_y_continuous(limits = c(0.10,0.4),labels=percent) +
scale_x_continuous(limits = c(0.10,0.4),labels=percent) +
labs(title ="10-40cm",y="Y",x="X")+
theme_update(plot.title=element_text(hjust=0.5))
Thank you in adavance!