Home > Software design >  R I Plotting a confidence interval for a logarithmic - exponential fitting
R I Plotting a confidence interval for a logarithmic - exponential fitting

Time:12-13

Let's suppose I have these two vectors:

 A <- c(0.06280179, 0.08216760, 0.07482619, 0.06823409, 0.06952835, 0.07018200,  0.06021379, 0.01093384, 0.01347112, 0.01426566, 0.02643976, 0.03703703, 0.04278447, 0.04821157, 0.05714920, 0.04756160, 0.02538775, 0.02267100, 0.02388572, 0.02309525, 0.0201453, 0.03132787, 0.03698205, 0.05634021, 0.06859215, 0.08044785, 0.08345671, 0.09029339, 0.08528164, 0.07538614, 0.01229222)
B <- c(0.06634636, 0.04257361, 0.04921238, 0.08225855, 0.11344899, 0.13373171, 0.14987047, 0.19256872, 0.14790440, 0.08028606, 0.06475687, 0.03736584, 0.05676217, 0.10489289, 0.17173170, 0.21296917, 0.27816564, 0.25458431, 0.29817322, 0.22127536, 0.15497217, 0.18341950, 0.14756396, 0.16856496, 0.13028875, 0.14073265, 0.11733407, 0.12458992, 0.12484860, 0.16910507, 0.28517631

I'm interested in adjust a logarithmic function and plotting the mathematical expression with a confidence interval in grey (as we can do with stat_smooth(aes(...), method = "lm")). How can I do that using ggplot2?

Thanks in advance.

CodePudding user response:

Update:

library(tidyverse)
df <- tibble(A, B)

ggplot(df,aes(A, B))  
  geom_point()  
  stat_smooth(method="lm",formula=y~log(x),fill="grey") 
  theme_bw()

enter image description here

First answer: Do you mean something like this:

library(tidyverse)
df <- tibble(A, B)

ggplot(df,aes(A, B))  
  stat_summary(fun.data=mean_cl_normal)   
  geom_smooth(method='lm', formula= y~x)

enter image description here

  • Related