使用 scatterplot3d 绘制球体 [英] Using scatterplot3d to plot a sphere

查看:48
本文介绍了使用 scatterplot3d 绘制球体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个所有氨基酸的 x,y,z 坐标矩阵.我使用以下函数在 3D 空间中绘制蛋白质:

I have a matrix of the x,y,z coordinates of all amino acids. I plot the protein in 3D space using the following function:

make.Plot <- function(position.matrix, center, radius){
  scatterplot3d(x = position.matrix[,4], y = position.matrix[,5], z = position.matrix[,6], type = 'o', color = 'blue')
}

position.matrix 中的每一行都对应一个不同的氨基酸.我想要做的是修改函数,所以如果我传递一个中心",它对应于位置矩阵(列出氨基酸编号)的第 2 列中的一个数字,以及一个半径,我想要一个球体以该氨基酸为中心.

Each row in the position.matrix is for a different amino acid. What I would like to do is modify the function so if I pass it a "center" which would correspond to a number in column 2 of position matrix (which lists the amino acid numberings), as well as a radius, I want a sphere with center at that amino acid.

例如,如果我传递它 (position.matrix, 9, 3),我希望它在氨基酸 9 周围绘制一个半径为 3 的球体.我在这里上传了位置数据的副本:http://temp-share.com/show/YgFHv2J7y

For instance, if I pass it (position.matrix, 9, 3), I want it to plot a sphere of radius 3 around amino acid 9. I have uploaded a copy of the position data here: http://temp-share.com/show/YgFHv2J7y

请注意,由于跳过了一些残基,因此行计数并不总是规范计数.我将始终通过规范"计数...

Notice that the row count is not always the canonical count as some residues are skipped. I will always pass it the "canonical" count...

感谢您的帮助!

推荐答案

这是您的代码经过测试的修改.它为 cex.symbols 添加一个长度为 2 大小的向量,该向量通过向逻辑向量加 1 来选择:

Here is a tested modification of your code. It adds a length-2 size vector for cex.symbols which is chosen by adding 1 to a logical vector:

make.Plot <- function(position.matrix, center, radius){
    scatterplot3d(x = position.matrix[,4], y = position.matrix[,5], 
                  z = position.matrix[,6], type = 'o', 
          cex.symbols=c(1,radius)[1+(position.matrix[,2]==center)],  color = 'blue')
          }

我想知道您是否真正想要的是 rgl 包.它具有形状和交互式绘图环境.使用 scatterplot3d,您可以使用以下代码将所选点设为红色:

I wonder if what you really want is the rgl package. It has shapes and an interactive plotting environment. With scatterplot3d you could make the chose point red with this code:

myplot <- make.Plot(position.matrix, 3, 9)
myplot$points3d(position.matrix[3 , 4:6],  col="red", cex=10)

我还找到了一些用于绘制参数球体"的代码,该球体可用于创建高亮指示器:

I also located some code to draw a "parametric sphere" which can be adapted to creating a highlighting indicator:

myplot <- make.Plot(position.matrix, 3, 9)
a=seq(-pi,pi, length=10);
myplot$points3d(x=2*c(rep(1, 10) %*% t(cos(a)))+position.matrix[3 , 4] , 
 y=2*c(cos(a) %*% t(sin(a)))+position.matrix[3 , 5],
 z=2*c(sin(a) %*% t(sin(a)))+position.matrix[3 , 6],
 col="red", cex=.2)

这篇关于使用 scatterplot3d 绘制球体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆