簡體   English   中英

為什么 plot_ly 在 plotly 繪制表面圖的 id 列?

[英]Why does plot_ly in plotly plot the id column for the surface plot?

我正在嘗試創建一些隨機數據的曲面圖,但我遇到了一個問題,其中 plot_ly 正在繪制矩陣的 id 列。

下面是代碼和隨機數據的一部分。

library(plotly)

random_data <- read_excel("Regression_Builder.xlsx", sheet = "Yield")
lm.O1 = lm(O1 ~ X1 + X2 + X3 + I(X1^2) + I(X3^2), data = random_data)

three_dims = data.frame(random_data$O1, random_data$X1, random_data$X2)
three_dims_mat = data.matrix(three_dims, rownames.force = NA)
#I saw a post that mentioned that using data.matrix can lead to issues and to instead use cbind.
#I attempted that and got the same results.

O1_surface = plot_ly(z = three_dims_mat[,1:3], type = "surface")
#I also tried with z = ~three . . . and also without the [,1:3]. Neither of these helped.
O1_surface

數據

如您所見,一列 ID 包含三列數據。 此外,唯一接近 5000 的列是 id 列。

當我創建曲面圖時,我得到了這個圖: 曲面圖

x 和 y 軸肯定是關閉的,看起來 y 軸只是 id 列?

我對 R 很陌生,所以我真的只是按照另一個頁面的說明進行操作,可以在這里看到: https : //plotly.com/r/3d-surface-plots/

他們似乎和我所做的沒有什么不同。 他們使用的數據直接來自 plotly,“volcano”的結構類似於我的矩陣。

我很感激你能提供的任何幫助!

編輯:有人要求提供數據樣本。 這是前 20 個數據點。

    X1               X2             X3
1   -568.4093212    -306.6656476    35.08753966
2   -758.2562177    -310.9201146    32.64751489
3   -467.4339846    -364.0556644    34.09746155
4   -529.7232277    -310.837259     36.28913812
5   -535.9391621    -323.411462     39.75818106
6   -494.4654867    -386.835529     30.5269416
7   -490.3442684    -363.7089394    33.8776127
8   -392.6493419    -327.10129      31.22857484
9   -720.6745211    -339.3230459    35.09282461
10  -425.0705298    -324.8479801    32.0451123
11  -529.9568075    -317.8269927    35.48054421
12  -445.4251925    -422.9827843    34.80734687
13  -730.3447224    -307.6357161    33.58775347
14  -309.4192505    -434.2465323    29.17980084
15  -609.6549563    -382.4879761    31.16542379
16  -731.8211673    -345.8748154    32.76108565
17  -745.736109     -299.1330659    36.46136652
18  -589.5006466    -368.9677558    31.87794536
19  -655.5712467    -344.9485136    32.50361267
20  -536.5405239    -401.9952118    30.72522988

我希望這有幫助。 謝謝!

好的,所以我在這里找到了根本原因。

正如我所擔心的,這主要是對 plot_ly 函數如何工作的誤解。 我原以為它的工作原理類似於 3D 散點圖,但回想起來沒有多大意義。

此函數僅需要高度值矩陣。 此矩陣的行和列代表您嘗試繪制的函數的 X 和 Y“輸入”。 我通過玩一個簡單的例子發現了這一點:

L = cbind(c(1, 1, 1), c(1, 2, 1), c(1, 1, 1))
plot_l = plot_ly(z = L, type = "surface")
plot_l

結果如下:

簡單曲面示例

對於遇到這個問題並想看看我是如何得到我想要的表面圖的人來說,下面是代碼和圖。 情節相對反氣候,x、y 軸在技術上不正確,但這是一個開始!

X1_V = -476:-233
X2_C = 33.96
X3_V = 185:423

pred_func = function(x1, x3) predict(lm.O1, newdata = data.frame(X1 = x1, X2 = X2_C, X3 = x3))

O1_surface = plot_ly(z = pred_mat, type = "surface")
O1_surface

精確的曲面圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM