在plot_ly曲面图上标记x、y和z轴(R)

发布于 2025-01-10 23:15:51 字数 347 浏览 3 评论 0原文

我有以下几行代码用于绘制曲面

      fig<-plot_ly(z=~MatDurMat,y=~MatDurAxis[,1],x=~MatDurAxis[,2],type = "surface")
 %>% layout(xaxis=list(title='Discount rate'), yaxis=list(title='Initial carbon price (£)'))
        fig

它可以很好地绘制曲面,但尽管没有出现任何错误,轴标题显示为 MatDurMat、MatDurMat[,1] 和 MatDurMat[,2],而不是我在布局部分指定的。

提前致谢。

I have the following lines of code for plotting a surface

      fig<-plot_ly(z=~MatDurMat,y=~MatDurAxis[,1],x=~MatDurAxis[,2],type = "surface")
 %>% layout(xaxis=list(title='Discount rate'), yaxis=list(title='Initial carbon price (£)'))
        fig

It plots the surface just fine, but despite not getting any errors, the axis titles show up as MatDurMat, MatDurMat[,1], and MatDurMat[,2], as opposed to the ones I have specified in the layout section.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ双果 2025-01-17 23:15:51

这应该可以做到:

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
  MatDurAxis <- cbind(1:25, seq(.01, .25, by=.01))
  MatDurMat <- outer(MatDurAxis[,1], MatDurAxis[,2], "*")
  MatDurAxis = as.data.frame(MatDurAxis)
  plot_ly(z=~MatDurMat,y=~MatDurAxis$V1,x=~MatDurAxis$V2, type = "surface") %>% 
    layout(scene = list(
      xaxis=list(title='Discount rate'),
      yaxis=list(title='Initial carbon price (£)'),
      zaxis=list(title='Z AXIS TITLE')))

reprex 包于 2022 年 3 月 1 日创建 (v2.0.1)

注意,您需要将 scene 用于 3d 轴。

This should do it:

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
  MatDurAxis <- cbind(1:25, seq(.01, .25, by=.01))
  MatDurMat <- outer(MatDurAxis[,1], MatDurAxis[,2], "*")
  MatDurAxis = as.data.frame(MatDurAxis)
  plot_ly(z=~MatDurMat,y=~MatDurAxis$V1,x=~MatDurAxis$V2, type = "surface") %>% 
    layout(scene = list(
      xaxis=list(title='Discount rate'),
      yaxis=list(title='Initial carbon price (£)'),
      zaxis=list(title='Z AXIS TITLE')))

Created on 2022-03-01 by the reprex package (v2.0.1)

Note, you need to use scene for 3d axes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文