別のプロット関数を呼び出して平滑化された線を追加するプロット関数を使用する単純なプロットを作成しています。2 番目の関数はlines()
、いくつかの標準の基本グラフィック引数を取ります。最初の関数も同じ名前の引数を使用します。ここで、最初のプロットを変更せずに、2 番目のプロットのいくつかの要素を変更したいと思います。私が考えることができる少なくともいくつかのオプションがあります:
- それぞれ別々にプロットする
- 関数を書き直して、一意の名前の引数を 2 番目のプロット関数に含めます。
- おそらくggplot2を使用して、このための新しいプロット関数を作成します
そして、ネストされた関数に引数の値を渡すことは、何も書き直さずに可能であると考えるようになりました。この質問では、プロットを行う関数を求めているわけではないことに注意してください-必要に応じて独自の関数を書くことができます.引数リストで引数を指定することが可能かどうか尋ねていtraceplot
ますlines
。 traceplot の名前付き引数でもあります。例:
require(coda)
require(geoRglm)
# Some example data
mcmc <- c(0, 0, 0, 0, 0.5, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0.5,
0.5, 1, 0.5, 0, 0.5, 0.5, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0.5, 0.5, 0, 0.5, 1, 0, 0.5, 1, 0.5, 0.5, 0.5, 0, 0.5, 0.5,
0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0.5, 0, 0, 0,
0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0.5, 1, 1, 0, 1, 0,
0, 0.5, 0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0, 1, 0.5,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5,
1.5, 1, 1.5, 1, 1, 1, 1, 0.5, 0.5, 1, 1, 1.5, 1.5, 1.5, 1, 1.5,
1.5, 1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5, 1, 1.5, 1.5,
1, 1.5, 1.5, 1, 1, 1, 1, 1)
# Input parameters for mcmc object
input <- structure(list(S.scale = 3.75e-05, Htrunc = "default", S.start = "default",
burn.in = 0, thin = 100, n.iter = 20000, phi.start = 0, phi.scale = 1), .Names = c("S.scale",
"Htrunc", "S.start", "burn.in", "thin", "n.iter", "phi.start",
"phi.scale"), class = "mcmc.geoRglm")
# create mcmc object
mcmc_obj <- create.mcmc.coda( mcmc , mcmc.input = input )
#Plot - smooth = TRUE draws the smooth line through the data
traceplot( mcmc_obj , smooth = TRUE , main = "Default")
# Changing the colour argument passes the same argument through to the lines function called to plot the smooth line
traceplot( mcmc_obj , smooth = TRUE , col = 2 , main = "Change colour to red")
# In the source code of traceplot 'lines()' is called to plot the smooth line.
# Can I specify a colour argument to be passed only to lines without altering
# the function?
# Excerpt from the source code of traceplot:
function (x, smooth = FALSE, col = 1:6, type = "l", ylab = "",
...)
{
... some code here then...
if (smooth) {
for (k in 1:nchain(x)) lines(lowess(xp, yp[, k])
}
}