【问题标题】:R plotly subplot warning 'layout' objects don't have these attributes: 'NA'R plotly subplot 警告“布局”对象没有这些属性:“NA”
【发布时间】:2021-05-10 07:14:15
【问题描述】:

我正在尝试组合两个情节图(type = 'mesh3d'type = 'scatter3d')。每个单独的地块都非常好,没有任何警告。在我使用subplot 后,每次尝试显示绘图时都会出现警告。

警告“布局”对象没有这些属性:“NA”

我试过suppressWarning,但这没有任何效果。

任何想法我在这里缺少什么来摆脱警告?

剧情版本:4.9.3 R 版本:4.0.1

# plot data
plt_data <- data.frame(maturity=rep(1:10, each=10),
                   tenor=rep(1:10, 10),
                   value=rnorm(100))

# plot 1
fig11 <- plot_ly(
           data=plt_data, x=~maturity, y=~tenor, z = ~value,
           type = "mesh3d",intensity = ~value,
           colors = colorRamp(c(
              rgb(168, 191, 173, max = 255),
              rgb(100, 181, 117, max = 255),
              rgb(0,100,80, max = 255)
           )),
           contour=list(show=T, width=4, color="#fff"),
           showscale = F,
           scene='scene1', 
           lighting = list(ambient = 0.9),
           hoverinfo="skip",
           source="myID"
) 


# plot 2
fig12 <- plot_ly(
           data=plt_data, x=~maturity, y=~tenor, z = ~value,
           type = "scatter3d",
           mode="markers",
           hovertemplate="Maturity: %{x:.f}<br>Tenor: %{y:.f}<br>Value: %{z:.4f}<extra></extra>",
           marker=list(
             symbol="square-open",
             size=4,
             color="#3d543f"
           ),
           scene='scene1',
           source="myID",showlegend=F
) 

# subplot which does throw a warning
subplot(fig11, fig12)

【问题讨论】:

    标签: r plotly warnings r-plotly


    【解决方案1】:

    关于警告有an open issue。这是隐藏此案例警告的解决方法 -

    function_to_hide_plotly_warning <- function(...) {
      plot <- subplot(...)
      plot$x$layout <- plot$x$layout[grep('NA', names(plot$x$layout), invert = TRUE)]
      plot
    }
    
    function_to_hide_plotly_warning(fig11, fig12)
    

    【讨论】:

    • 我发现了这个未解决的问题,但无法将其翻译成 R. Thx!
    【解决方案2】:

    对于 R 和 Shinyapps,抑制这样的警告:

    options(warn = -1)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 2020-01-07
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多