本文介绍了密谋-表面-文本hoverinfo无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用plotly构建了一个表面图,并且尝试基于自己的文本获取hoverinfo.奇怪的是,它不再起作用了.

library(plotly)
x <- rnorm(10)
y <- rnorm(10)
z <- outer(y, x)

p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface",
             text = ~paste0("My X = ", x, "\n My Y = ", y, "\n My Z = ", z),
             hoverinfo = "text") %>% layout(dragmode = "turntable")
print(p)

尽管

p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface") %>% layout(dragmode = "turntable")

效果很好.

我也试图用<br />替换\n无效.

我在macOS Sierra上使用R 3.4.0和4.7.0.

有什么建议吗?

matrix传递,那么它将起作用.

custom_txt <- paste0("My X = ", rep(x, times = 10),
                    "</br> My Y = ", rep(y, each = 10), # correct break syntax
                    "</br> My Z = ", z) %>%
    matrix(10,10) # dim must match plotly's under-the-hood? matrix

plot_ly(x = ~x, y = ~y, z = ~z, type = "surface",
             text = custom_txt,
             hoverinfo = "text") %>%
    layout(dragmode = "turntable")

I have build a surface chart with plotly and I am trying to have hoverinfo based on my own text. Curiously it is not working anymore.

library(plotly)
x <- rnorm(10)
y <- rnorm(10)
z <- outer(y, x)

p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface",
             text = ~paste0("My X = ", x, "\n My Y = ", y, "\n My Z = ", z),
             hoverinfo = "text") %>% layout(dragmode = "turntable")
print(p)

Although

p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface") %>% layout(dragmode = "turntable")

works well.

I have also tried to substitute \n by <br /> with no effect.

I am using R 3.4.0 and plotly 4.7.0 on macOS Sierra.

Any suggestions?

解决方案

Plotly's labeling seems finicky with custom labels using the ~paste() syntax because it is trying to build a new data structure with your inputs (three vectors and one matrix), but if you pass in custom labels as a matrix with the same dimensions it will work.

custom_txt <- paste0("My X = ", rep(x, times = 10),
                    "</br> My Y = ", rep(y, each = 10), # correct break syntax
                    "</br> My Z = ", z) %>%
    matrix(10,10) # dim must match plotly's under-the-hood? matrix

plot_ly(x = ~x, y = ~y, z = ~z, type = "surface",
             text = custom_txt,
             hoverinfo = "text") %>%
    layout(dragmode = "turntable")

这篇关于密谋-表面-文本hoverinfo无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 19:45