0

次のようなデータフレームがあります。

z<-data()

      cost time Period Type
    1    72   51     10    1
    2    68   60     10    1
    3    79   43     10    1
    4    67   79     10    1
    5    79   67     10    1
    6    89   35     10    1
    7    80   34     10    1
    8    78   45     10    1
    9    76   47     10    1
    10   69   57     10    1
    11   67   56     10    1
    12   69   45     10    1
    13   79   57     10    1
    14   70   56     10    1
    15   80   56     10    1
    16   89   56     10    1
    17    3    5      1    0
    18    5    8      2    0
    19   89   67      3    0
    20   46   56      4    0
    21   23   34      5    0

プロジェクト タイプ 0 とプロジェクト タイプ 1 の間のマハラノビス距離を次のように描画します。

  x<-z[,c(1,2)]
require(robustbase)
  x.mcd=covMcd(x)
   title(main="Distance from benchmark space", col.main="red", font.main=4)

  drawMahal(x,center=x.mcd$center,covariance=x.mcd$cov,quantile = c(0.975, 0.75, 0.5, 0.25,0.01) ,m =1000,lwdcrit =2 ,col=ifelse(x1$Type==1,"green","blue"),pch=2,col.axis="blue",frame.plot=TRUE,cex=2)
  legend("top",pch=c(2,2),col=c("green","blue"),c("Current","Benchmark"),bty="o",box.col="darkgreen",cex=.8)
  axis(1, col = "blue",col.axis = "blue",  lwd = 0.5,tck=1,col.ticks="light gray")
  axis(2, col = "blue", col.axis = "blue", lwd = 2,tck=1,col.ticks="light gray")

したがって、出力は次のようになります。 マハラノビス距離

Q1: データフレーム z から上記のグラフに周期の軸を追加して、グラフを 3D 形状にする方法を教えてください。

Q2 青い点からマハラノビス空間の重心に線を追加しますか? そして期間1~5の青い点からそれぞれ別の色で線を追加します。

私は plot_ly を使用して 3D にしましたが、それでも楕円を描くことができませんでした。

f<-plot_ly(n,x=n$cost,y=n$time,z=n$Period,color = n$Type,type="scatter3d", mode="markers")

私が得たグラフは次 のとおりです3D ナビゲーション 。楕円については、次のコードを書きましたが、何も表示されません。

z <- layout(f, title = 'Highlighting Regions with Circles', 
                                   shapes = list(
                                    list(type = 'circle',
                                 xref = 'x', x0 = min(f$cost), x1 = max(f$cost),
                        yref = 'y', y0 = min(f$time), y1 = max(f$time),zref='z',z0=1,z1=1,
                                    fillcolor = 'blue', line = list(color = 'red'),
                            opacity = 0.1)))
4

0 に答える 0