如果您希望绘图考虑行和列名,则需要将它们作为参数传递(见下文)。
PS:下次请使用
dput(head(mdf))
共享您的数据。
library(plotly)
mdf <- structure(list(`0.25` = c(0.1099018, 0.1107301, 0.1096955, 0.1081831,
0.1070853, 0.1067455), `0.5` = c(0.1075803, 0.1069789, 0.1057843, 0.1055844,
0.104627, 0.1040249), `0.75` = c(0.1060026, 0.1049246, 0.1037788, 0.1041088,
0.1035221, 0.102821), `1` = c(0.1048713, 0.1035827, 0.1025263, 0.1031551,
0.102875, 0.1021501), `2` = c(0.1026496, 0.101343, 0.1005516, 0.1016053,
0.1018182, 0.1013992), `3` = c(0.101568, 0.10060837, 0.09989326, 0.1009812,
0.10118515, 0.10130785), `4` = c(0.10040423, 0.09977042, 0.09913758,
0.10020332, 0.10035681, 0.10093757), `5` = c(0.09918249, 0.09876087,
0.09828665, 0.09935368, 0.09950923, 0.10034346), `7` = c(0.09782469,
0.09755911, 0.09744314, 0.09857824, 0.09881024, 0.09963237), `10` =
c(0.09941434, 0.09913463, 0.09923485, 0.10051402, 0.10080843, 0.10130524 ),
`15` = c(0.1013165, 0.1007016, 0.1015744, 0.1032524, 0.1036377, 0.1043398),
`20` = c(0.09823009, 0.09737618, 0.09906617, 0.1008646, 0.10126557,
0.10207753), `25` = c(0.1002991, 0.0996668, 0.1009025, 0.1024462, 0.1027223,
0.1032627), `30` = c(0.1150025, 0.114767, 0.1154665, 0.1175229, 0.1177263,
0.1183408)), class = "data.frame", row.names = c("1991-01-02", "1991-01-03",
"1991-01-04", "1991-01-07", "1991-01-08", "1991-01-09" ))
plot_ly(
z = ~ as.matrix(mdf),
x = ~ as.Date(rownames(mdf)),
y = ~ as.numeric(colnames(mdf)),
type = "surface",
colorbar = list(title = "My surface plot")
) %>% layout(scene = list(
xaxis = list(title = "X-Axis"),
yaxis = list(title = "Y-Axis"),
zaxis = list(title = "Z-Axis")
))