简体   繁体   中英

Using scatterplot3d to plot a sphere

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')
}

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.

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...

Thanks for your help!

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')
          }

在此处输入图片说明

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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM