I am new to R and I\'m having some difficulty plotting an exponential curve using ggplot2. I have a set of data below.
DATA
As rightly mentioned in the comments, the range of log(y)
is 3.19 - 4.09. I think you simply need to bring the fitted values back to the same scale as y so try this. Hopefully helps...
library(ggplot2)
df <- read.csv("test.csv")
linear.model <-lm(y ~ x, df)
log.model <-lm(log(y) ~ x, df)
exp.model <-lm(y ~ exp(x), df)
log.model.df <- data.frame(x = df$x,
y = exp(fitted(log.model)))
ggplot(df, aes(x=x, y=y)) +
geom_point() +
geom_smooth(method="lm", aes(color="Exp Model"), formula= (y ~ exp(x)), se=FALSE, linetype = 1) +
geom_line(data = log.model.df, aes(x, y, color = "Log Model"), size = 1, linetype = 2) +
guides(color = guide_legend("Model Type"))