# I want to represent an exponential growth in R

Hello,
I want to represent an exponenial growth withn the dataset :
Annee;Obs
2009;5,0
2010;6,0
2015;30,0
2016;100,0
2017;110,0
2018;120,0
2019;250,0
2022;1000,0

My code is this
library(ggplot2)
library(tidyr)
library(tidyverse)
library(lubridate)
library(ggthemes)
plot(traject)
dfTR <- data.frame(traject)
ggplot(dfTR, aes(x = Annee, y = Obs))+
ggtitle("Trajectoire dorée")+
xlab("Année")+
ylab("Indice de majoration")+
geom_point()+
geom_smooth(color="gold", fill="gold4")

trajD <- lm(log(Obs)~ Annee, data=dfTR)
summary(trajD)

I have the result
Call:
lm(formula = log(Obs) ~ Annee, data = dfTR)

Residuals:
Min 1Q Median 3Q Max
-0.45886 -0.09723 0.02878 0.19425 0.33773

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -817.00703 49.49012 -16.51 3.15e-06 ***
Annee 0.40738 0.02455 16.59 3.06e-06 ***

With the log transformation, I have the equation of the curve
Obs = exp^(0.40738*Annee-817.007)
My main question : I want to represent this fot the values of x between 2002 and 2030 with ggplot2

its not super clear to me what you want, but it may be something like this

``````
(newd_1 <- data.frame(Annee=2002:2030))
newd_1\$pred_log_obs <- predict(trajD,
newdata=newd_1)
newd_1\$pred_obs <- exp(newd_1\$pred_log_obs)

newd_2 <- bind_rows(dfTR,newd_1)

ggplot(newd_2,
aes(x = Annee, y = Obs))+
ggtitle("Trajectoire dorée")+
xlab("Année")+
ylab("Indice de majoration")+
geom_point()+
geom_smooth(color="gold", fill="gold4") +
geom_smooth(aes(y=pred_obs),
color="red",fill="red",alpha=.1)``````
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.