首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以图形方式显示3d外框轴线

以图形方式显示3d外框轴线
EN

Stack Overflow用户
提问于 2017-11-01 18:23:03
回答 1查看 93关注 0票数 2

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

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2017-11-02 01:00:39

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47052659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档