我正在尝试使用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数组(即,每个x =点[,1],y =点[,2],z =点[,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"
或类似的混合轮廓方式。
关于如何策划这个的任何想法?
这是有帮助的情节
答案 0 :(得分:2)
对于那些被淹在这里的人来说是解决方案
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