2016-04-19 18 views
0

ファセットタイルプロットの最小BIC値を強調表示しようとしています。スタックチャンスをうかがっファセットタイルプロットの個々の値をハイライト表示

set.seed(1000) 
tseries<-data.frame("value"=rnorm(300, 50, 7.5)) 
BICs<- apply(expand.grid(0:2,0:2,0:2),1L, 
       function(rw)BIC(arima(tseries$value,order=rw))) 
ARIMA<-expand.grid(0:2,0:2,0:2) 
names(ARIMA)<-c("p","d","q") 
ARIMA$BICs<-BICs 
ARIMA$d<-paste("d=",ARIMA$d,sep="") 

ggplot(ARIMA, aes(x=q, y=p)) + 
    geom_tile(aes(fill = BICs)) + 
    geom_text(aes(label = round(BICs,2)),colour="yellow",fontface="bold",size=4) + 
    scale_fill_gradient(low = "cyan", high = "blue4")+ 
    facet_wrap(~d,nrow=2) 

smallest value is the ARIMA(p=1,d=1,q=1) specification

それは右の矩形美学を持つ新しいデータフレームを呼び出すことであろう単一の値の周りにボックスを描画するための最善の解決策のように思える

best<-data.frame("xmin"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),3]-.5, 
         "xmax"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),3]+.5, 
         "ymin"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),1]-.5, 
         "ymax"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),1]+.5, 
         "d"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),2], 
         "BIC"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),4]) 
best$d<-factor(best$d,levels=levels(as.factor(ARIMA$d))) 

が、 geom_rectの美学を入れようとするとエラーが出る

答えて

1

arimaのベストデータフレームにpqベクターを作成しておくべきである

best<-data.frame("q"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),3], 
       "p"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),1], 
       "d"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),2], 
       "BIC"=ARIMA[which(ARIMA$BICs==min(ARIMA$BICs)),4]) 
best$d<-factor(best$d,levels=levels(as.factor(ARIMA$d))) 

、その後geom_rectが

geom_rect(data=best,aes(xmin=q-.5,xmax=q+.5,ymin=p-.5,ymax=p+.5),colour="yellow",alpha=0) 

enter image description here

いつものように動作します
関連する問題