2

反復的な方法で得られた残差の行列があります。各列は特定の単位の残差に対応し、各行は手順のステップに対応します。さまざまな反復にわたる各ユニットの残差の軌跡を示す折れ線グラフを作成したいと思います。さらに、各軌跡の最後に、対応するユニットを示すテキスト ラベルを追加したいと思います。

私が書いたコードは次のとおりです

# extract the residuals as a data frame 
res <- data.frame(Fout$Fresid)

# add a clumn that indicates the Forward step

# obtain the number of observations in the series and the number of Forward 
steps
 n <- ncol(res)
totstep = nrow(res)

# define a variable that indicates the step of the forward search
Fstep = seq(1:totstep)

#scale the residuals
res <- res/sqrt(Fout$Fsigma2[totstep])

res = cbind(Fstep,res)

# assign column names to the data frame
unitlabel = sprintf("r%03d", 1:n)
colnames(res) = c('idxSearch', unitlabel)

# threshold values
q1 = qnorm(0.99)

# reshape data
plot_res <- melt(res, id.var= 'idxSearch', variable.names = 
colnames(res[,-1]))

# plot the data
FresP <- ggplot(data = plot_res, aes(x=idxSearch, y=value, group=variable, 
colour=value)) +
geom_line(size = 1.05) + 
scale_colour_gradient(low = 'purple', high = 'green', breaks = c(-8,0,8)) + 
scale_x_continuous(limits = c(0,totstep)) + 
geom_text(data = plot_res, aes(x= totstep, y=value, 
                            label =variable)) +
geom_hline(yintercept = q1, linetype="dotted", color = "#FF6600", size = 
1.07) + 
geom_hline(yintercept = -q1, linetype="dotted", color = "#FF6600", size = 
1.07)

そして、私が得たプロットは次のとおりです

軌道プロット

ただし、テキストラベルを線の近くに置き、まばらではないようにしたいと思います。誰でも助けてくれますか??

どうもありがとう

4

0 に答える 0