【发布时间】:2020-12-23 07:31:51
【问题描述】:
我正在尝试为我拥有的一些随机数据创建一个曲面图,但我遇到了一个问题,即 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,“火山”的结构类似于我的矩阵。
感谢您提供的任何帮助!
编辑:有人要求提供数据样本。这是前 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
我希望这会有所帮助。谢谢!
【问题讨论】:
-
请包含您的数据样本。