简体   繁体   English

绘图显示 3d 外框轴

[英]plotly show 3d outer box axis

I use the following code to create aa 3d scatterplot in plotly:我使用以下代码在 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

And get this plot: plot并得到这个情节:情节

My question is, how can I add a line that will show the outer side of the box on the axis?我的问题是,如何添加一条线来显示轴上框的外侧? something like that: required plot类似的东西:所需的情节

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM