我正在尝试使用plotly在3D绘图上从点到x-y轴制作垂直线。这对于3D图形的可读性来说似乎很重要,否则在图形方面看起来很棒,但在经过大量搜索之后我无法找到如何做到这一点。
例如,使用scatterplot3d()时,可以通过简单地添加 type =“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")
})
但是情节看起来好多了,而且比scatterplot3d()更通用....任何建议?谢谢!
答案 0 :(得分:0)
我得到了Carson Sievert在情节社区论坛上的回答,以防有人感兴趣。编写函数group2NA()(从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)