[英]R plotly subplot warning 'layout' objects don't have these attributes: 'NA'
我正在嘗試組合兩個 plotly 數字( type = 'mesh3d'
和type = 'scatter3d'
)。 每個單獨的地塊都非常好,沒有任何警告。 使用subplot
后,每次嘗試顯示 plot 時都會出現警告。
警告“布局”對象沒有這些屬性:“NA”
我試圖suppressWarning
,但這沒有任何效果。
我在這里缺少什么來擺脫警告的任何想法?
Plotly 版本: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)
關於警告有一個未解決的問題。 這是隱藏此案例警告的解決方法 -
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 和 Shinyapps,要抑制這樣的警告:
options(warn = -1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.