2016-04-29 16 views
1

私はパラセタモール過量の監査を行っています。私は血中濃度と摂取後の時間の散布図を作成しています。しかし、治療は血液レベルがラインの上または下にあるかどうかによって左右される。y=1986*0.840897^tここで、tは時間であり、y =値の血液レベルはt=4:16である。ggplot2の場合、散布図にカーブを追加するにはどうすればよいですか?

このような関数を分散プロットの上に重ねるには、どうすればggplot2ですか?

基本的に私は少し、このようなものを作りたい:

答えて

4

は、独自の関数を定義するstat_function()に渡し、あなたはすべてのセットです。

set.seed(357) 

# simulate some data, rnorm() is used to add some noise 
x <- seq(from = 4, to = 6, length.out = 10) 
y <- 1986*0.840897^x + rnorm(10, sd = 30) 
xy <- data.frame(x, y) 

# define function 
myfun <- function(x) 1986*0.840897^x 

library(ggplot2) 

ggplot(xy, aes(x = x, y = y)) + 
    theme_bw() + 
    geom_point() + 
    stat_function(fun = myfun) 

enter image description here

関連する問題