我想覆盖在顶部的线的Plotly等高线图,类似于覆盖在基质的图像上的线,其中所述强度表示位置z内R3:
# Generate an arbitrary matrix
m <- matrix(sin(1:6^2) * 1:6, nrow = 6)
# Define a path
path <- data.frame(x = c(0:7), y = c(0, 1, 2, 2, 3, 3, 4, 6))
image(x = 1:6, y = 1:6, z = m, col = gray.colors(20), xlab = "x", ylab = "y")
lines(path$x, path$y)
Run Code Online (Sandbox Code Playgroud)
其中呈现:
使用 Plotly,我尝试过
library(plotly)
plot_ly(x = 1:6, y = 1:6, z = t(m), type = "contour") %>%
add_lines(x = path$x, y = path$y)
Run Code Online (Sandbox Code Playgroud)
这会生成一个覆盖有空白线框R3而不是一条线的等高线图:
MLa*_*oie 11
你可以试试这个:
plot_ly(x = 1:6, y = 1:6, z = t(m), type = "contour") %>%
add_trace(x = c(1, 2, 3, 4, 5, 6), y = c(1, 2, 3, 3, 4, 5), type = "scatter", mode = "line")
Run Code Online (Sandbox Code Playgroud)
它几乎给了你你想要的。希望能帮助到你!