【问题标题】:plotly show 3d outer box axisplotly 显示 3d 外框轴
【发布时间】:2017-11-02 01:00:38
【问题描述】:

我使用以下代码在 plotly 中创建一个 3d 散点图:

library(plotly)
A <- c(50,20,0)
B <- c(50,0,30)
C <- c(50,0,0)
D <- c(50,20,30)
E <- c(0,0,30)
F <- c(0,20,0)
G <- c(0,0,0)
H <- c(0,20,30)
classes <- c("A","B","C","D",
             "E","F","G","H")
conceptual <- rbind(data.frame(),A,B,C,D,
                    E,F,G,H)
colnames(conceptual) <- c("X","Y","Z")
conceptual$labels <- classes
scene = list(camera = list(eye = list(x = 2.5, y = -1.5, z = 1.25)))
p <- plot_ly(conceptual, x = ~X, y = ~Y, z = ~Z, text = ~labels) %>%
  add_markers() %>% 
  add_text() %>% 
  layout(scene=scene,showlegend = FALSE)
p

得到这个情节: plot

我的问题是,如何在轴上添加一条线来显示框的外侧?类似的东西: required plot

【问题讨论】:

    标签: r plotly


    【解决方案1】:
    library(plotly)
    A <- c(50,20,0);  B <- c(50,0,30);  C <- c(50,0,0);  D <- c(50,20,30)
    E <- c(0,0,30);   F <- c(0,20,0);   G <- c(0,0,0);   H <- c(0,20,30)
    classes <- c("A","B","C","D","E","F","G","H")
    conceptual <- rbind(data.frame(),A,B,C,D,E,F,G,H)
    colnames(conceptual) <- c("X","Y","Z")
    conceptual$labels <- classes
    
    l1 <- subset(conceptual, labels %in% c("E","B"))
    l2 <- subset(conceptual, labels %in% c("D","B"))
    l3 <- subset(conceptual, labels %in% c("C","B"))
    
    scene = list(camera = list(eye = list(x = 2.5, y = -1.5, z = 1.25)))
    p <- plot_ly(conceptual, x = ~X, y = ~Y, z = ~Z, text = ~labels) %>%
      add_markers() %>% 
      add_text() %>% 
      add_trace(x=~X, y=~Y, z=~Z, data=l1, 
                type='scatter3d', mode='lines',
                line = list(color = "black", width = 4, dash='dash')) %>%
      add_trace(x=~X, y=~Y, z=~Z, data=l2, 
                type='scatter3d', mode='lines',
                line = list(color = "black", width = 4, dash='dash')) %>%
      add_trace(x=~X, y=~Y, z=~Z, data=l3, 
                type='scatter3d', mode='lines',
                line = list(color = "black", width = 4, dash='dash')) %>%
      layout(scene=scene,showlegend = FALSE)
    p
    

    【讨论】:

    • 谢谢。但是,我在 plotly 中寻找可以做到这一点的功能。你知道一个吗?
    • @idoklein 抱歉,我不明白,我的解决方案仅使用 plotly 命令,它回答了您的问题。为什么不行?你有什么需求?
    猜你喜欢
    • 1970-01-01
    • 2018-08-04
    • 2021-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-20
    • 2020-10-19
    • 1970-01-01
    相关资源
    最近更新 更多