我想在绘制等高线图的顶部覆盖一条线,类似于在一个矩阵的图像上覆盖一条线,在矩阵中,强度表示R3
中z
中的位置
# 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)
它会渲染:
使用Plotly,我尝试了
library(plotly)
plot_ly(x = 1:6, y = 1:6, z = t(m), type = "contour") %>%
add_lines(x = path$x, y = path$y)
这会生成一个等高线图,其中覆盖了一个空R3
空间的线框,而不是一条线:
发布于 2018-06-10 00:58:20
你可以试试这个:
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")
它几乎满足了你的需求。希望它能帮上忙!
https://stackoverflow.com/questions/50774908
复制相似问题