在两点之间用r 3d箭头绘制

时间:2018-07-22 11:58:06

标签: r 3d arrows r-plotly

我想在两点之间画箭头。这就是问题所在,我用图形程序绘制了三个箭头来解释我的问题。

enter image description here

那是我的源代码:

require(plotly)

a <- c(5,16,16,17,18,23,25,27,37,42,5)
b <- c(13,12,26,15,14,6,10,22,14,25,17)
c <- c(12,14,25,26,8,9,27,30,31,26.5,12)

ap <- c(5,12,16,17,11,23,25,27,37,21.5,5)
bp <- c(13,12,26,15,14,6,10,22,14,12.5,17)
cp <- c(12,14,25,26,8,9,27,30,31,26,12)

rnn <- c("U1", "U2", "U3", "U4", "U5", "U6", "U7", "U8", "U9", "U10", "U11")

m <- list( symbol = 200, size = 8, line = list( color = toRGB("yellow"), width = 2 ) ) 
m1 <- list( symbol = "triangle", color="black", sizemod = "diameter", size = 5, line = list( color = "black", width = 2 ) )

plot_ly(x = ap, y = bp, z = cp) %>%

  add_trace(marker = m1, type = "scatter3d", mode = "text+markers", 
        name = "projected", linetypes = NULL, text = rnn) %>%
  add_trace(x = a, y = b, z = c, marker = m, type = "scatter3d", mode = "text+markers", 
        name = "original", linetypes = NULL, text = rnn) 

非常感谢。

1 个答案:

答案 0 :(得分:0)

并不是您要找的东西,但是您可以尝试以下方法:

aaa <- c(16, 12)
bbb <- c(12, 12)
ccc <- c(14, 14)

aaaa <- c(18, 11)
bbbb <- c(14, 14)
cccc <- c(8, 8)

aaaaa <- c(42, 21.5)
bbbbb <- c(25, 12.5)
ccccc <- c(26.5, 26)

plot_ly() %>%
  add_trace(x = aaa, y = bbb, z = ccc, type = "scatter3d", mode = "lines", 
            name = "lines", showlegend = FALSE) %>%
  add_trace(x = aaaa, y = bbbb, z = cccc, type = "scatter3d", mode = "lines", 
            name = "lines", showlegend = FALSE) %>%
  add_trace(x = aaaaa, y = bbbbb, z = ccccc, type = "scatter3d", mode = "lines", 
            name = "lines", showlegend = FALSE) %>%
  add_trace(x = ap, y = bp, z = cp, marker = m1, type = "scatter3d", mode = "text+markers", 
            name = "projected", linetypes = NULL, text = rnn) %>%
  add_trace(x = a, y = b, z = c, marker = m, type = "scatter3d", mode = "text+markers", 
            name = "original", linetypes = NULL, text = rnn)

enter image description here