[英]Labelling x,y, and z axis on plot_ly surface plot (R)
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.它很好地绘制了表面,但尽管没有出现任何错误,轴标题显示为 MatDurMat、MatDurMat[,1] 和 MatDurMat[,2],而不是我在布局部分指定的那些。
Thanks in advance.提前致谢。
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)由reprex package (v2.0.1) 创建于 2022-03-01
Note, you need to use scene
for 3d axes.请注意,您需要为 3d 轴使用
scene
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.