layout
によって生成できる関数の4番目の例ではexample(layout)
、通常の分布からのサンプルの棒グラフに折れ線グラフを重ねたいと思います。
、、試しましたがlines()
、plot( , add=TRUE)
運がありませんでした。
どうやってやるの?または、使用とは別のルートを取る必要がありlayout
ますか?
質問する
290 次
1 に答える
0
これが1つのアプローチです:
library(TeachingDemos)
x <- pmin(3, pmax(-3, stats::rnorm(50)))
y <- pmin(3, pmax(-3, stats::rnorm(50)))
xhist <- hist(x, breaks=seq(-3,3,0.5), plot=FALSE)
yhist <- hist(y, breaks=seq(-3,3,0.5), plot=FALSE)
top <- max(c(xhist$density, yhist$density))
xrange <- c(-3,3)
yrange <- c(-3,3)
nf <- layout(matrix(c(2,0,1,3),2,2,byrow=TRUE), c(3,1), c(1,3), TRUE)
layout.show(nf)
par(mar=c(3,3,1,1))
plot(x, y, xlim=xrange, ylim=yrange, xlab="", ylab="")
par(mar=c(0,3,1,1))
bx.out <- barplot(xhist$density, axes=FALSE, ylim=c(0, top), space=0)
updateusr( bx.out[1:2], 0:1, xhist$mids[1:2], 0:1 )
xdens <- density(x)
lines(xdens$x, xdens$y, col='blue')
par(mar=c(3,0,1,1))
by.out <- barplot(yhist$density, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE)
updateusr( 0:1, by.out[1:2], 0:1, yhist$mids[1:2] )
ydens <- density(y)
lines(ydens$y, ydens$x, col='blue')
バーの「高さ」が密度と一致するように、からcounts
への変更に注意してください。また、TeachingDemosパッケージの使用法が座標系と一致するようになっています。代わりに、関数にとを指定することもできます。density
updateusr
updateusr
width
xlim
barplot
于 2012-08-01T18:25:34.450 に答える