Mesh3d how to color the face of triangles R Dense

I'm trying to create a mesh3D plot in plotlyR using R studio, but I'm having trouble how to create a color scale for my mesh.

I have a nice grid section using code,

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

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

      

(from what I found from the website to make it plotable, but this is not the grid color I want) 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

      

I'm not really sure what the complexion, intensity, or color does, but I want to map a different color scale on the grid based on the bi value I measured for each xyz -array point (ie each point x = points [, 1 ], y = points [, 2], z = points [, 3] has the bi value assigned to it in my dataframe). And I want to scale the color where

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"

      

or similar in contour blending mode.

Any thoughts on how to do this?

here is the plot if it helps

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

+1


source to share


1 answer


For those who are here there is a solution

    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

    )

      

Above was the code to build. face $ color was done like this.

Using the following function to convert each face to the mean of the measured vector bi



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

      

then converting the zmean value to color

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

      

+2


source







All Articles