繁体   English   中英

将拟合指数方程添加到 ggplot 2

[英]Add fitted exponential equation into ggplot 2

我在图上显示拟合指数方程时遇到问题。 我使用 ggplot2 和stat_smooth()来绘制点和拟合线。 现在我想在绘图上显示拟合方程,但stat_poly_eq()不起作用。 有谁知道这是怎么做到的吗? 我的代码附在这里。

mydata = data.frame("conc_ensemble" = c( 2.000000, 2.477121, 2.778151, 2.954243, 3.000000, 3.477121, 3.778151, 3.954243, 4.000000,
                                 4.477121, 4.778151, 4.954243, 5.000000, 5.477121, 5.778151, 5.954243, 6.000000), 
            "REV" = c(5.20000, 3.76000, 2.23000, 1.96000, 1.57500, 1.00000, 0.71250, 0.65000, 0.49000, 0.28300, 0.22900, 0.17500,
                      0.16225, 0.08830, 0.06075, 0.06075, 0.05350))

my.formula = y ~ a*exp(b*x)
ggplot(mydata, aes(conc_ensemble, REV) ) +
  geom_point() +
  stat_smooth(method = 'nls', method.args = list(start = c(a=1, b=1)), 
              formula = my.formula, colour = 'red', se = FALSE) +
  stat_poly_eq(formula = my.formula,
               label.x.npc = 0.2,  size = 3,
               aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")), 
               parse = TRUE,
               rr.digits = 3)

这是你要找的吗? stat_function应该完成这项工作。

library(tidyverse)

mydata = data.frame("conc_ensemble" = c( 2.000000, 2.477121, 2.778151, 2.954243, 3.000000, 3.477121, 3.778151, 3.954243, 4.000000,
                                         4.477121, 4.778151, 4.954243, 5.000000, 5.477121, 5.778151, 5.954243, 6.000000), 
                    "REV" = c(5.20000, 3.76000, 2.23000, 1.96000, 1.57500, 1.00000, 0.71250, 0.65000, 0.49000, 0.28300, 0.22900, 0.17500,
                              0.16225, 0.08830, 0.06075, 0.06075, 0.05350))

my.formula = y ~ a*exp(b*x)

ggplot(mydata, aes(conc_ensemble, REV) ) +
    geom_point() +
    stat_smooth(method = 'nls', method.args = list(start = c(a=1, b=1)), 
                formula = my.formula, colour = 'red', se = FALSE) +
    stat_function(fun = my.formula,
                 label.x.npc = 0.2,  size = 3,
                 aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")), 
                 parse = TRUE,
                 rr.digits = 3)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM