R Plotly-曲面-文本悬停信息不工作

R Plotly-曲面-文本悬停信息不工作,r,plotly,R,Plotly,我已经用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

我已经用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)
library(plotly)

xPlotly的标签似乎对使用
~paste()
语法的自定义标签很挑剔,因为它试图用输入(三个向量和一个矩阵)构建新的数据结构,但如果将自定义标签作为具有相同维度的
矩阵
传入,它将起作用

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")
custom_txt%
矩阵(10,10)#尺寸必须与发动机罩下的plotly匹配?矩阵
plot_-ly(x=~x,y=~y,z=~z,type=“surface”,
text=custom_txt,
hoverinfo=“text”)%%>%
布局(dragmode=“转盘”)

感谢您的帮助。它被要求保留
\n
而不是

,但我不知道为什么。就我的实际情况而言,我不得不将
time=10
each=10
颠倒过来。这正是我所需要的。谢谢
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")