2016-03-25 24 views
2

例で作成されたような通常の曲線の下の2つの区間の間の領域を色付け/シェードしたいと思います。間隔は125かもしれない:140または140ラティスの曲線下の色の領域

library(lattice) 

e4a <- seq(60, 170, length = 10000) 
e4b <- dnorm(e4a, 110, 15) 
xyplot(e4b ~ e4a, 
    type = "l", 
    scales = list(x = list(at = seq(60, 170, 5)), rot = 45), 
    panel = function(x, ...){ 
      panel.xyplot(x, ...) 
      panel.abline(v = c(110, 125, 95, 140, 80, 95), lty = 2) 
    }) 

enter image description here

を超えたセグメント私はR graphic base systemのための本当に簡単な解決策を見つけたが、私は、ラティスのための同等の解決策を見つけることができませんでした。

+1

@ Hack-R That's base graphics。 –

答えて

4

panel.polygonが存在する:ポリゴンが正しい取得と

xyplot(e4b ~ e4a, 
     type = "l", 
     scales = list(x = list(at = seq(60, 170, 5)), rot = 45), 
     panel = function(x,y, ...){ 
      panel.xyplot(x,y, ...) 
      panel.abline(v = c(110, 125, 95, 140, 80, 95), lty = 2) 

      xx <- c(125, x[x>=125 & x<=140], 140) 
      yy <- c(0, y[x>=125 & x<=140], 0) 
      panel.polygon(xx,yy, ..., col='red') 
     }) 

少し厄介。

あなたのデータにはe4aがソートされています。そうでない場合は、panel.polygonにプレゼンテーションする前に並べ替える必要があります。

enter image description here

関連する問題