Plotly 3D线下填充

9
我想使用Plotly绘制一个针对时间序列的3D线图,并在每条线下填充。这里有一个示例代码。
library(plotly)

dens <- with(diamonds, tapply(price, INDEX = cut, density))
data <- data.frame(
  x = unlist(lapply(dens, "[[", "x")),
  y = unlist(lapply(dens, "[[", "y")),
  cut = rep(names(dens), each = length(dens[[1]]$x)))

p <- plot_ly(data, x = ~cut, y = ~x, z = ~y, type = 'scatter3d', mode = 'lines', color = ~cut)
p

使用这段代码,我可以生成这个图表。
3D线图而不填充。

enter image description here

我已经尝试过surfaceaxis=0,1或2,但它们产生了错误的填充。
3D-Plotly带有错误的填充。

enter image description here

我希望的是填充x轴和线图之间的区域。
这是另一组值的示例3D图,填充曲线下方。
作为一个示例,这是一个带有填充曲线下方的3D图。

enter image description here

可以有人提供一种方法吗?先谢谢了。

编辑:必须使用“plotly”包创建。


不是R特定的问题,而是plotly包中的错误。我们应该等待发布:https://github.com/plotly/plotly.py/issues/1206 - M--
https://github.com/plotly/plotly.js/issues/2352 - M--
2个回答

7
如果您可以接受伪3D,您可以制作一个山脊线密度图。我相信也有一个Plotly版本可用。
免责声明:我是ggridges包的作者。
library(ggplot2)
library(ggridges)

ggplot(diamonds, aes(x = price, y = cut, fill = cut)) +
  geom_density_ridges(scale = 2, alpha = 0.7) +
  scale_fill_brewer(guide = guide_legend(reverse = TRUE)) +
  scale_y_discrete(expand = c(0.01, 0)) +
  theme_ridges(center = TRUE)

enter image description here


3

更新:

据我所知,这似乎是 plotly 中的一个 bug。在填充曲线下方时,它不考虑点的顺序并且不是 R 特有的。

请参见 GitHub 上的此问题:https://github.com/plotly/plotly.py/issues/1206



您可以尝试使用 latticeExtra::cloud。当然,它不会像 plotly 一样提供交互式图表。

rle_x <- rle(as.numeric(factor(data$cut)))$lengths

mcolor <- c("red","blue","green","purple", "yellow")    

data$mcolor<-rep(mcolor[seq_along(rle_x)],times = rle_x)
    
cloud(y~x+cut, data, panel.3d.cloud=panel.3dbars, 
      xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1), 
      par.settings = list(axis.line = list(col = "transparent")),
      col.facet = data$mcolor,
      col = data$mcolor)

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接