私は結合しようとしています。つまり、値がまったく異なる2つの変数を持つxyplot(回帰直線付き)で棒グラフをオーバーレイしようとしています。
これが私のデータです:https ://www.dropbox.com/s/aacbkmo577uagjs/example.csv
以下のコードに従ってパネルに表示される2つの数値変数「rb」と「rae」およびいくつかの因子変数(sample.size、effect.size、allocation.design、true.dose)があります。変数「rae」は棒グラフで(理想的には背景のかすかな色で)表示する必要がありますが、変数「rb」は回帰直線のあるxyplotで表示する必要があります。2つの主な質問があります:
(1)両方のタイプのグラフを組み合わせる/オーバーレイする方法は?(2)軸ラベルをカスタマイズする方法(yスケールの異なるスケール)
(1)については、さまざまな種類のグラフをggplot2と組み合わせる方法を知っていますが、ラティスでも可能であるはずですよね?うまくいかない「doubleYScale」を試してみました。
(2)の場合、「scales」オプションのyスケールに「relation ='free'」を使用することだけを達成しました(コードを参照)。値の重要な範囲に焦点が当てられているので、これは素晴らしいことです。ただし、軸ラベルを外側の左側と右側に追加で描画する方が適切です(それぞれ「rae」と「rb」の場合)。
これまでのコードは次のとおりです(Dieter Menneによって自己完結型に変更されました)
library(lattice)
library(latticeExtra)
df.dose <- read.table("example.csv", header=TRUE, sep=",")
df.dose <- transform(df.dose,
sample.size=as.factor(sample.size),
true.dose = as.factor(true.dose))
rae.plot <- xyplot(
rae ~ sample.size | allocation.design*true.dose,
df.dose, as.table=TRUE,
groups = type,
lty = 1, jitter.x=TRUE,
main="RAE",
scales=list(y=list(draw=F, relation="free", tck=.5)),
panel = function(x,y) {
panel.xyplot(x,y,jitter.x=TRUE)
panel.lmline(x,y, col="darkgrey", lwd=1.5)
})
useOuterStrips(rae.plot)
rb.plot <- barchart(
rb ~ sample.size | allocation.design*as.factor(true.dose),
df.dose, as.table=TRUE,
groups = type,
key=list(
text=list(levels(as.factor(df.dose$type))),
scales=list(y=list(draw=F, relation="free", tck=.5)),
main="RB"))
useOuterStrips(rb.plot)