2017-05-08 177 views
0

我试图用plotly在3D图上从点到x-y轴做垂直线。这对于3D图形的可读性来说似乎很重要,否则这些图形看起来很不错,但是我经过大量搜索后无法找到任何位置。在R中使用阴谋的3D阴谋的下降线?

例如,使用scatterplot3d()的时候,这可以通过简单地将线路类型=“H”像在本实施例中完成的:

library(scatterplot3d) 
with(mtcars, { 
    scatterplot3d(disp, wt, mpg,   # x y and z axis 
       color="blue", pch=19, # filled blue circles 
       type="h",    # lines to the horizontal plane 
       main="3-D Scatterplot Example", 
       xlab="Displacement (cu. in.)", 
       ylab="Weight (lb/1000)", 
       zlab="Miles/(US) Gallon") 
}) 

但是plotly看起来好得多和比scatterplot3d()更通用....任何建议?谢谢!

回答

0

我从积极的社区论坛上得到了Carson Sievert的回答,以防有人感兴趣。在对函数组2NA()进行编程(从https://github.com/ropensci/plotly/blob/master/R/group2NA.R复制并粘贴)之后,下面的工作将会完成,虽然有点笨拙:

library(plotly) 

mtcars$id <- seq_len(nrow(mtcars)) 
ms <- replicate(2, mtcars, simplify = F) 
ms[[2]]$mpg <- 0 
m <- group2NA(dplyr::bind_rows(ms), "id") 

plot_ly(color = I("black"), showlegend = F) %>% 
    add_markers(data = mtcars, x = ~disp, y = ~wt, z = ~mpg) %>% 
    add_paths(data = m, x = ~disp, y = ~wt, z = ~mpg)