r - 使用 plotly (RStudio) 绘制 3D 曲面函数
问题描述
我正在使用,我想知道是否可以在 RStudio 中绘制曲面函数 f(x,y)=z。实际上,我想绘制一架飞机。现在,我正在绘制的是这样的:
fit3 <- lm(y1~x1+ealax2,data = datos2)
# Outer part ~~~~~~~~~~~~~~~~~~~~~
x <- (0:250)/250
y <- (0:250)*100
beta <- fit3$coefficients
fxy <- function(x,y){
beta[1] + beta[2]*x + beta[3]*y
}
z <- outer(X = x,Y = y,FUN = fxy)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plot_ly(x=x,y=y,z = t(z), type = "surface") %>%
add_trace(data = datos2, x = ~x1, y = ~ealax2, z = ~y1,
mode = "markers", type = "scatter3d",
marker = list(size = 5, color = "red"))
我得到了这个:
我想要的不是做“外部”部分,即:
x <- (0:250)/250
y <- (0:250)*100
beta <- fit3$coefficients
fxy <- function(x,y){
beta[1] + beta[2]*x + beta[3]*y
}
z <- outer(X = x,Y = y,FUN = fxy)
所以事情会更容易。我的意思是,有更简单的方法可以在 R 中绘制 y=f(x) 函数,例如:
curve(cos(x),from=-2,to=5)
而且我正在寻找这样的东西,但在情节上,而且还有 3D 情节。有没有办法做到这一点,或者最后是 2D 版本?
您将能够从这个站点下载我的数据:datos2.csv
解决方案
推荐阅读
- node.js - Mongoose 查询过滤器
- typo3 - 如何在 TYPO3 前端显示 rte 内容时省略 html 标签?
- python - Tkinter ~ 如何在网格框中分隔元素
- c - 如何使 for 循环在 C 中工作得更慢?
- laravel - HTTP 405 方法不允许流明/Laravel
- html - 链接仅在断开时显示
- python - 我可以导入 scikit-learn,但我不能使用它
- c# - 如何将 ExecuteScriptAsync 结果输入到变量中?
- html - 在 css SEGOE UI 中使用 Windows 字体 - 是否允许?
- visual-studio-code - 有没有办法从 vscode 扩展访问 env?