简体   繁体   English

R Shiny Plotly 3D:将 x、y、z 轴的标题更改为实际变量名称并添加图例标题

[英]R Shiny Plotly 3D : Change the title of x , y , z axis to actual variable name and add legend title

I have created a 3D scatter plot using plotly() on R shiny App.我在 R shiny App 上使用plotly()创建了一个 3D 散点图。 The code is as below:代码如下:

output$threeDscatterPlot <- renderPlotly({
    data <- dataInput()$data
      plot.obj <<-list() 
      plot.obj$data <<- data 
      var7 <<- with(plot.obj$data,get(input$variable7)) 
      var8 <<- with(plot.obj$data,get(input$variable8)) 
      var9 <<- with(plot.obj$data,get(input$variable9)) 
      var10 <<- with(plot.obj$data,get(input$variable10)) 
      var10 <-  as.factor(var10)
      print(names(plot.obj$data))
p <- plot_ly(plot.obj$data, x = var7, y = var8 , z = var9 , type = "scatter3d", mode = "markers" , 
              color = var10 , colors = "Paired" ) 
       p %>%  layout(legend = list(x = 1, y = 0.5 , bgcolor = "#E2E2E2"))

 })

var7, var8, var9 are continous variable & var 10(categorical variable. var7、var8、var9 是连续变量和 var 10(分类变量。

3D Plotly graph is coming very clearly but xaxis labels, yaxis labels and zaxis labels are comingas var 7, var8, var 9 3D Plotly 图形非常清晰,但 xaxis 标签、yaxis 标签和 zaxis 标签作为 var 7、var8、var 9 出现

My question is: How can we change the title of x, y, z axis to the actual variable name of var7/8/9 as in dataset/dataframe?我的问题是:我们如何将 x、y、z 轴的标题更改为数据集/数据帧中 var7/8/9 的实际变量名称? I tried using xaxis.zaxis, yaxis but it does not seem to work How can we add the legend title just above the legend?我尝试使用 xaxis.zaxis、yaxis,但它似乎不起作用我们如何在图例上方添加图例标题?

All done in R Shiny App全部在 R Shiny App 中完成

Thanks in Advance提前致谢

Add the following to your layout object:将以下内容添加到您的布局对象:

layout(scene = list(xaxis = list(title = 'your title')))

more info here: https://plot.ly/r/reference/#layout-scene-xaxis-title更多信息在这里: https ://plot.ly/r/reference/#layout-scene-xaxis-title

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM