使用ggplot或R

时间:2018-06-27 05:48:16

标签: python plot ggplot2 graph line

我有一个数据表,其中包含9个数据子集,每个子​​集我都想拟合一条曲线。我曾尝试在R中使用ggplot()plot()函数,但似乎无法理解在哪里插入命令以在同一图形上绘制9条不同的曲线。

这是我的数据表,我已经对其进行了调整,使其具有三列,即“ PAR”,“ TMP”和“ VAL”。

PAR   `16.5`  `18` `19.5`  `21` `22.5`  `24` `25.5`  `27`
<chr>  <dbl> <dbl>  <dbl> <dbl>  <dbl> <dbl>  <dbl> <dbl>
1 0       0.06  0.06   0.06  0.06   0.06  0.06   0.06  0.06
2 6       1.47  1.54   1.42  1.6    1.6   1.63   1.67  1.44
3 18      4.08  4.34   3.87  4.72   4.68  4.88   4.94  3.78
4 35      5.2   5.7    5.23  7.04   7.05  7.7    7.63  5.06
5 61      5.46  6.04   5.72  8.18   8.41  9.47   8.97  5.68
6 93      5.01  5.57   5.35  7.68   8.3   9.47   8.49  5.51
7 121     4.08  4.4    4.43  6.29   6.97  8.07   6.83  4.35
8 195     2.96  3.29   3.19  4.82   5.44  6.55   5.28  3.21
9 268     1.3   1.77   1.66  2.74   2.96  3.6    2.88  1.91


     PAR  TMP   VAL
   <chr> <chr> <dbl>
 1     0 16.5   0.06
 2     6 16.5   1.47
 3    18 16.5   4.08
 4    35 16.5   5.2 
 5    61 16.5   5.46
 6    93 16.5   5.01
 7   121 16.5   4.08
 8   195 16.5   2.96
 9   268 16.5   1.3 
10     0 18     0.06
# ... with 62 more rows

这是我使用line()使用的代码:

EQYfit <- data.frame(PAR=c(RLCxmelt$PAR), 
                     VAL=c(RLCxmelt$VAL))
nonlin <- function(t, a, b, c) { (a/b) * exp( -(t-c)/b - exp(-(t-c)/b) ) }
nlsfit <- nls(VAL ~ nonlin(PAR, a, b, c), data=EQYfit, start=list(a=1000, b=50, c=75))

with(EQYfit, plot(PAR, VAL, cex=0.5, ylim=c(0,12)))
EQYseq <- seq(0,270,.1)
VAL <- coef(nlsfit)
print(VAL)
lines(EQYseq, nonlin(EQYseq, VAL[1], VAL[2], VAL[3]))

但这只给了我9条曲线的平均值的一条曲线。

使用ggplot()函数,我设法使其绘制了9条曲线。使用loess时,我似乎无法正确获得代码:

nls

这是我想通过双指数衰减函数实现的:

Desirable outcome

谢谢。

0 个答案:

没有答案