【问题标题】:Overlaying line on contour plot using Plotly使用 Plotly 在等高线图上叠加线
【发布时间】:2018-11-19 08:33:59
【问题描述】:

我想在 Plotly 等高线图上叠加一条线,类似于在矩阵的图像上叠加一条线,其中强度表示 zR3 中的位置:

# 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 空间而不是一条线:

【问题讨论】:

    标签: r plotly r-plotly


    【解决方案1】:

    你可以试试这个:

    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")
    

    它几乎可以满足您的需求。希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-04
      • 2021-12-21
      • 2018-08-31
      • 2020-01-19
      • 2021-11-25
      • 2015-01-08
      • 1970-01-01
      • 2017-07-24
      相关资源
      最近更新 更多