如何在R中使用plotly更改3D曲面图中的轴标签

eblbsuwk  于 2023-01-03  发布在  其他
关注(0)|答案(1)|浏览(133)

我有一个2D矩阵(11行,20列)(平均速度),其中第一列是渗透率,第一行(标题)是交通量,单元格是平均速度。
| | 一百|二百|三百|四百|
| - ------|- ------|- ------|- ------|- ------|
| [1、]|三十八点五|三十八点一|三十七点七|三十七点二|
| [2、]|三十八点二|三十七点七|三十七点五|三十六点九|
完整数据集在这里:https://laesze-my.sharepoint.com/emoji symbols:x/g/personal/borsos_attila_o365_sze_hu/EciUlfLjKY5PiLLJJk6v4xEB9qfpU1FA3WrHRaKc7HPKLA?e=nZYbYa
使用plotly我有这个表面图:https://chart-studio.plotly.com/~borsosa/1/#/

p<- plot_ly(z= ~avgspeed)
p <- p %>% add_surface() %>%
  layout(title = "3D surface plot of average speed",
          legend = list(title = list(text="Average speed")), 
         scene = list(
    xaxis = list(title = "traffic volume [veh/h]"),
    yaxis = list(title = "penetration [%]"),
    zaxis = list(title = "average speed [km/h]")))

我有两个问题无法解决:
1.如何更改图例标题(从avgspeed更改为Average speed)
1.我希望在x轴上看到从100到2000(seq(100,2000,by = 100))的流量,在y轴上看到从0到100(seq(0,100,by = 10))的渗透率

wfsdck30

wfsdck301#

这里有两个问题和两个答案...

  1. colorbar=list(title='Example 1'),如下面的代码所示。
    1.在下面的代码中使用range(c(100,2000))ticks = 100
    资料来源:

代码:

library(tidyverse)
library(plotly)

data = matrix(data = rnorm(100),nrow = 10,ncol = 10)

p = plot_ly() %>% 
  add_trace(z = ~data,
            name = 'ZED',
            type = 'surface',
            colorbar=list(title='Example 1'))

p %>% 
  layout(
    scene = list(
      xaxis = list(title = 'xaxis',range = c(0,20)),
      yaxis = list(title = 'yaxis'),
      zaxis = list(title = 'zaxis')
    ),
    margin = list(
        b = 40, 
        l = 60, 
        r = 10, 
        t = 25
      )
  )

相关问题