【问题标题】:Fitting comparison plot_Algorithm for several dependent variables in R拟合 R 中几个因变量的比较 plot_Algorithm
【发布时间】:2017-12-13 02:02:14
【问题描述】:

我的数据集中有几个因变量,我想找到 x 和每个 y 之间的最佳拟合。如何修改以下代码(循环函数)以同时绘制 x 和所有 y 的图。我不想单独运行每个因变量的代码,而是想运行一个代码并为 (x,y) (x,y1) 和 (x,y2) 绘制三个图

fit1 <- read.table(header=TRUE,text="
x    y   y1 y2
1 0 2.36 3  5
2 1 1.10 3  6
3 2 0.81 4  7
4 3 0.69 1.3  8
5 4 0.64 2.3  9
6 5 0.61 4.3  15")
Various fits:

library(ggplot2)
ggplot(fit1,aes(x,y))+geom_point()+
    geom_smooth(method="glm",se=FALSE,
                method.args=list(family=gaussian(link="log")))+
    geom_smooth(method="nls",se=FALSE,
                formula=y~a+b*exp(-c*x),
                method.args=list(start=list(a=0.6,b=1.5,c=1)),
                colour="red")+
    geom_smooth(method="lm",se=FALSE,
                formula=y~exp(-x),
                colour="purple")

【问题讨论】:

    标签: regression


    【解决方案1】:

    融合数据后可以使用 facet_grid

    fit1_melt <- melt(fit1, id = "x")
    ggplot(fit1_melt, aes(x=x,y=value)) + 
    geom_point() + 
    facet_grid(~variable)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-09
      • 2017-06-20
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多