考虑从Plotly获取的这个例子:
library(plotly)
# volcano is a numeric matrix that ships with R
p <- plot_ly(z = ~volcano) %>% add_surface()
p
注意如果你悬停,有一个很好的跟踪显示x(矩阵的行索引),y(列索引)和z(给定行和列的矩阵内容)。如何将轴和更改为“Measure1”,“Measure2”,“Measure3”而不是x,y,z?我试过layout()
,但我提出的并不是削减它。这是我的尝试,但“zaxis”不是一个东西,其他标签不会改变,
library(plotly)
# volcano is a numeric matrix that ships with R
p <- plot_ly(z = ~volcano) %>% add_surface() %>%
layout (xaxis = list(title = "Measure1", showgrid = F),
yaxis = list(title = "Measure2"),
zaxis = list(title="Measure3")
)
p
我确定我错过了一些基本的东西,但我被困住了。热烈欢迎任何帮助。
答案 0 :(得分:3)
从user2510479扩展先前的答案:
您可以通过scene
和xaxis
/ yaxis
/ zaxis
title
为Plotly曲面图设置轴标签。
hoverinfo可以通过text
设置,hoverinfo
需要是一个与z值具有相同尺寸的数组。 text
需要library(plotly)
txt <- array(dim=dim(volcano))
for (x in 0:dim(volcano)[[2]] - 1) {
for (y in 0:dim(volcano)[[1]] - 1) {
txt[1 + x*dim(volcano)[[1]] + y] = paste('Measure1: ', x, '<br />Measure2: ', y, '<br />Measure3: ', volcano[1 + x * dim(volcano)[[1]] + y])
}
}
p <- plot_ly(z = volcano,
text = txt,
hoverinfo = 'text') %>% add_surface()
p <- layout(p, scene = list(xaxis = list(title = "Measure1"),
yaxis = list(title = "Measure2"),
zaxis = list(title = "Measure3")
)
)
p
才能显示这些值。
atomic
答案 1 :(得分:2)
p <- plot_ly(z = ~volcano) %>% add_surface() %>%
layout(title = "Layout options in Volcano plot",
scene = list(
xaxis = list(title = "Measure1"),
yaxis = list(title = "Measure2"),
zaxis = list(title = "Measure3")))
p