summaryrefslogtreecommitdiff
path: root/R/kinplot.R
blob: ace12700a0f091ab3a01ae45f827ea93d5ec9168 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
kinplot <- function(kinobject, 
	xlab = "Time [days]", ylab = "Parent [% of applied radioactivity]",
        ylim = c("auto", "auto"),
	lpos = "topright")
{
	kindata <- na.omit(kinobject$data)
	kinfits <- kinobject$fits
        if (ylim[1] == "auto") ylim[1] <- 0
        if (ylim[2] == "auto") ylim[2] <- max(kindata$parent)
        ylim <- as.numeric(ylim)
        
	plot(kindata$t, kindata$parent,
	  xlab = xlab,
	  ylab = ylab,
	  ylim = ylim
        )
	n.m <- length(kinfits)
	colors <- ltys <- 1:n.m
	names(colors) <- names(ltys) <- names(kinfits)
        ltext <- paste(kinobject$parent, "measured")
	for (kinmodel in names(kinfits))
	{
		m = kinfits[[kinmodel]]
		if(class(m) == "nls") {
			switch(kinmodel,
				SFO = curve(SFO(x, 
					coef(m)[["parent.0"]], 
					coef(m)[["k"]]),
					from = min(kindata$t), to = max(kindata$t), add=TRUE,
					col = colors[[kinmodel]],
					lty = ltys[[kinmodel]]),
				FOMC = curve(FOMC(x, 
					coef(m)[["parent.0"]],
					coef(m)[["alpha"]],
					coef(m)[["beta"]]),
					from = min(kindata$t), to = max(kindata$t), add=TRUE,
					col = colors[[kinmodel]],
					lty = ltys[[kinmodel]]),
				HS = curve(HS(x, 
					coef(m)[["parent.0"]], 
					coef(m)[["k1"]],
					coef(m)[["k2"]],
					coef(m)[["tb"]]),
					from = min(kindata$t), to = max(kindata$t), add=TRUE,
					col = colors[[kinmodel]],
					lty = ltys[[kinmodel]]),
				DFOP = curve(DFOP(x, 
					coef(m)[["parent.0"]], 
					coef(m)[["k1"]],
					coef(m)[["k2"]],
					coef(m)[["g"]]),
					from = min(kindata$t), to = max(kindata$t), add=TRUE,
					col = colors[[kinmodel]],
					lty = ltys[[kinmodel]]))
                        ltext <- c(ltext, paste("Fitted", kinmodel, "model"))
		} else {
                        ltext <- c(ltext, paste(kinmodel, "model failed"))
                        ltys[[kinmodel]] <- NA
		} 
	}
	legend(lpos, bty="n", inset = 0.05, 
		legend = ltext,
		pch = c(1, rep(NA, n.m)),
		lty = c(NA, ltys),
		col = c(1, colors))
}

Contact - Imprint