r - R中的颜色编码球体plot3d
问题描述
我有在 R 中创建球体的纬度和经度。我需要做的是根据相应的幅度为球体着色。它是 excel 文件中的 3 列:纬度、经度和振幅。所以每一行都是一个数据点。我得到的是一个统一的模式 - 它不能从幅度列中读取值。
test$x<-0.5*cos(test$lat)*cos(test$long)
test$y<-0.5*cos(test$lat)*sin(test$long)
test$z<-0.5*sin(test$lat)
test$color<-test$amplitude
ramp<- colorRamp(c("blue", "red"))((test$color)/max(test$color))
plot3d(x= test $x,y= test $y,z= test $z,xlim=c(-0.6,0.6), ylim=c(-0.6,0.6),zlim=c(-0.6,0.6),xlab = "X", ylab = "Y", zlab = "Z", col=test$color)
预期结果是根据幅度对每个 x、y、z 点进行着色。sphere_4
解决方案
您计算ramp
了 ,但没有使用它。该colorRamp
函数返回一个 RGB 值矩阵,不能用作 ; 中的颜色rgl
。您需要使用该rgb()
功能转换为颜色。例如,使用一些虚假数据:
test <- data.frame(lat = runif(2000, -89, 89)*pi/180,
long = runif(2000, 0, 359)*pi/180 )
test$x <- 0.5*cos(test$lat)*cos(test$long)
test$y <- 0.5*cos(test$lat)*sin(test$long)
test$z <- 0.5*sin(test$lat)
test$amplitude <- test$z
test$color <- abs(test$amplitude)
ramp <- colorRamp(c("blue", "red"))((test$color)/max(test$color))
ramp <- rgb(ramp, maxColorValue = 255)
library(rgl)
plot3d(x=test$x, y=test$y, z=test$z, xlab = "X", ylab = "Y", zlab = "Z", col=ramp)
这将产生以下图:
推荐阅读
- java - 手动删除 Tomcat 中 ServletContext(应用程序范围)的属性
- android - WebView 到顶部的滚动距离
- python - python中如何删除分号前的所有字母?
- arrays - 是否有 pyarrow 数组生成器
- android - 如何通过dataBinding访问fragment中activity的父视图
- asp.net-core - 如何在 ASP.NET Core 中禁用响应解压?
- javascript - 检查 localStorage 中的值是否以字符串和 console.log() 值名称开头
- tensorflow - Why Spark ML perceptron classifier has high F1-score while the same model on TensorFlow performs very badly?
- devexpress - 无法将用户可控参数链接到查询:DevExpress Report and Dashboard Server
- maven - Tomcat 8 战争部署 LifecycleException:无法启动组件