Plotly 3d Surface跟踪不显示零值

时间:2017-04-18 17:25:08

标签: r matrix plotly surface

当c2 = 2.111 * c1 + 21.1111 * c3时,我正在构建一个解析z值(又称c2)的3d图。当我创建以下代码时看起来很好(参见下面的代码),但如果你悬停,当c1或c3为零时,绘图轨迹不会显示值 - 这些点只是不显示!我不清楚我是否搞乱了基础数据,或者这是否是一个我可以通过一些额外参数解决的情节显示问题。

感谢任何提示。下面的代码应该足以说明我遇到的困难。

# First create the values for the visualization
myGrid <- expand.grid(seq(0, 100, 1), seq(0, 100, 1))
names(myGrid) <- c("c1", "c3")
myGrid$c2 <- 2.111111*myGrid$c1 + 21.111111*myGrid$c3

# go from long to wide, with c2 "inside" -- like a contingency table
c2 <- reshape(myGrid, direction = "wide", idvar = "c1", timevar = "c3")
names(c2) <- NA

# make it a matrix.  Remove the row name col.
c2 <- as.matrix(c2[,-1])


library(plotly)

# Then create the textual labels
txt <- array(dim=dim(c2))
for (x in 0:(dim(c2)[[2]]-1)) {
  for (y in 0:(dim(c2)[[1]] - 1)) {
    txt[1 + x*dim(c2)[[1]] + y] = paste('c1: $', x, '<br />c3: $', y, '<br />c2: $', c2[x+1,y+1])
  }
}

# create the plot
p <- plot_ly(z = c2,
             text = txt,
             hoverinfo = 'text') %>% add_surface()
p <- layout(p, 
            title = "<b>Maximum Cost Combinations for Drug Testing</b><br>(Cost Combinations Falling on or Below Plane are Good Testing Candidates)",
            margin = list(

              pad = 4
            ),
            scene = list(xaxis = list(title = "c1"), 
                            yaxis = list(title = "c3"), 
                            zaxis = list(title = "c2"),
                            camera = list(eye = list(x = -1.7, y = 1.5, z = 1))
)
)

p

0 个答案:

没有答案