本文介绍了mesh3d如何对三角形的面进行着色R绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a mesh3D plot in plotlyR using R studio but I am having problems with how to create a colour scale to my mesh.

我使用代码有一个不错的网格图,

I have a nice mesh plot using the code,

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/

(the above I found from, a website just to make it plot, but it is not the mesh colour scale 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

我不太确定面部的颜色是什么,强度或色阶是什么,但是我想基于一个名为bi的值将不同的色阶映射到网格上,我对xyz中的每个点都进行了测量-array(即,每个x = points [,1],y = points [,2],z = points [,3] point在我的数据帧中均分配有bi值).我想将颜色缩放到

I'm not very sure what face colour does, intensity does or colour scale does, but I want to map a different colour scale onto the mesh based on a value called bi, that I have measured for each point in the xyz-array (ie, each x = points[, 1], y = points[, 2], z = points[, 3] point has a value of bi assigned to it in my dataframe). And I want to scale the colour 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"

或类似形状的轮廓.

关于如何绘制此图的任何想法?

Any thoughts on how to plot this?

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

here is the plot if that helps

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

推荐答案

对于那些对此感兴趣的人是解决方案

For those who are interrsted here is the 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

    )

上面是要绘制的代码.face $ colour如下进行.

The above was the code to plot. face$colour was made as follows.

使用以下功能将每个人脸转换为测量向量bi的平均值

Using the below function to convert each face into a mean value of the measured vector bi

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

然后将zmean的值转换为颜色

then transforming the value of zmean into a colour

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

这篇关于mesh3d如何对三角形的面进行着色R绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:48