I am trying to do a exponential regression in ggplot2. So first my skript:
g <- ggplot(data, aes(x=datax, y=datay), color="black") +
geom_point(shape=1) + stat_smooth(method = 'nls', formula = y~a*exp(b*x), aes(colour = 'Exponential'), se = FALSE)
g <- g + theme_classic()
g <- g + theme(panel.grid.major=element_blank())
g <- g + theme(panel.grid.minor=element_blank())
g <- g + theme(axis.line.x=element_line(color="black"),
axis.line.y=element_line(color="black"),
panel.border=element_blank(),
panel.background=element_blank())
g <- g + labs(x="\ndatax",y="datay\n")
g <- g + theme(axis.text.y=element_text(size=14))
g <- g + theme(axis.text.x=element_text(size=14))
g <- g + theme(axis.title.y=element_text(size=18,vjust=1))
g <- g + theme(axis.title.x=element_text(size=18,vjust=1))
g
This is the image that I got
As a R-beginner I did the script by mixing scripts of mine and the internet. I always get the following error:
"In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing ‘a’, ‘b’ to '1.'.Consider specifying 'start' or using a selfStart model"
I did not found a better way to do the exponential graph, yet.
In addition, I would like to change the color of the graph into black and delete the legend and I would like to have the R² and p value in the graph. (maybe as well the confidence intervals?)