【问题标题】:mesh3d how to colour the faces of the triangles R Plotlymesh3d如何为三角形的面着色R Plotly
【发布时间】:2026-01-14 05:35:01
【问题描述】:

我正在尝试使用 R studio 在 plotlyR 中创建一个 mesh3D 图,但我遇到了如何为我的网格创建色标的问题。

我有一个很好的使用代码的网格图,

zmean <- apply(faces, MARGIN=1, function(row){mean(points[row,3])})

facecolor = colour_ramp(
    brewer_pal(palette="RdBu")(9)
)(rescale(x=zmean))

(上面是我从一个网站上找的,只是为了让它绘图,但它不是我想要的网格色标)http://moderndata.plot.ly/trisurf-plots-in-r-using-plotly/http://moderndata.plot.ly/trisurf-plots-in-r-using-plotly/

p <- plot_ly(
    x = points[, 1], y = points[, 2], z = points[, 3],
    i = faces[, 1]-1, j = faces[, 2]-1, k = faces[, 3]-1,
    type = "mesh3d",
    facecolor = "red",
)

p

我不太确定面部颜色、强度或色标的作用,但我想根据一个名为 bi 的值将不同的色标映射到网格上,我已经为 xyz 中的每个点测量了该值-array(即,每个 x = points[, 1], y = points[, 2], z = points[, 3] 点在我的数据框中都有一个 bi 值)。我想缩放颜色的位置

vert$colour[vert$bi<= 0.5] <- "red"
vert$colour[vert$bi> 0.5 & vert$bi<=1.5] <- "green"
vert$colour[vert$bi>= 1.5] <- "purple"

或类似的混合轮廓方式。

关于如何绘制这个有什么想法吗?

如果有帮助的话,这里是情节

https://plot.ly/~neilsrini/1377/points-2-vs-points-1/

【问题讨论】:

    标签: r plotly r-plotly


    【解决方案1】:

    对于那些感兴趣的人来说,这里是解决方案

        p1 <- plot_ly(
        x = points[, 1], y = points[, 2], z = points[, 3],
    
        i = faces[, 1]-1, j = faces[, 2]-1, k = faces[, 3]-1,
    
        type = "mesh3d",
    
       facecolor = face$colour
    
        )
    

    以上是要绘制的代码。 face$color 制作如下。

    使用下面的函数将每个人脸转换为测量向量bi的平均值

        zmean <- apply(faces, MARGIN=1, function(row){mean(bipts[row,1])})
    

    然后将zmean的值转换成颜色

        face$colour[zmean<= 0.5] <- "#800026" etc etc
    

    【讨论】:

      最近更新 更多