[R] some help with plotting a beautiful structure using rgl

Nair, Murlidharan T mnair at iusb.edu
Thu Aug 13 19:00:54 CEST 2009


Hi!!

I need some help in using the correct required symbol when plotting my DNA structure  using rgl. I need to plot one strand using empty circles and the other using filled circles and if possible have sequence in the center.
I tried using pch and lty but have not been able to get it to do what I want. I am appending my code below. I have inserted comments when I need help.
Thanks../Murli
 
library(rgl)
library(scatterplot3d)
computed.DNA.Str<-structure(list(X = 1:42, x = c(-0.975688, 4.652834982, 8.346905102, 
8.792265494, 5.763378778, 0.360110242, -5.410741675, -9.545558939, 
-10.41359287, -7.820469283, -2.87048497, 2.431822597, 5.780004735, 
5.864231475, -0.975688, -6.231531328, -9.096244856, -8.635565445, 
-4.93169249, 0.543553939, 5.641749313, 8.344319111, 7.415095348, 
3.257938171, -2.65307139, -8.1739403, -11.27397708, -11.05239614, 
0, 0, -0.074701006, -0.224103017, -0.373505029, -0.522907041, 
-0.672309052, -0.895991523, -1.193954453, -1.491917383, -1.789880313, 
-2.087843243, -2.459247906, -2.904094302), y = c(9.258795, 8.06401752, 
4.005465268, -1.499800943, -6.27267078, -8.411524903, -7.02084845, 
-2.355659798, 3.731366626, 9.104012958, 11.86675929, 11.12097881, 
7.538500525, 2.530292144, -9.258795, -6.917027485, -1.948188504, 
3.969960475, 8.447831953, 9.853576509, 7.728792788, 2.983125505, 
-2.290127499, -6.144106768, -6.950074829, -4.243530894, 1.04920276, 
7.296442545, 0, 0, 0.102817114, 0.308451342, 0.514085569, 0.719719797, 
0.925354025, 1.233226533, 1.643337323, 2.053448113, 2.463558902, 
2.873669692, 3.384864355, 3.997142893), z = c(-1.8, -5.19, -8.715110209, 
-12.46924956, -16.02528991, -19.31616462, -22.3760913, -25.15391125, 
-27.76053562, -30.76224274, -34.29278833, -38.28392979, -42.58508407, 
-47.00216668, 1.8, -1.59, -4.696196709, -7.756123397, -11.04699811, 
-14.60303845, -18.3571778, -22.4500669, -26.44120835, -29.97175395, 
-32.97346107, -35.58008544, -37.79845079, -40.14850635, 0, -3.39, 
-6.775228801, -10.1556864, -13.53614401, -16.91660161, -20.29705921, 
-23.66323008, -27.01511421, -30.36699834, -33.71888247, -37.07076661, 
-40.3989289, -43.70336934), seq = structure(c(2L, 2L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 1L, 1L), .Label = c("A", "T"), class = "factor")), .Names = c("X", 
"x", "y", "z", "seq"), class = "data.frame", row.names = c(NA, 
-42L))

dnaStr<-as.data.frame(computed.DNA.Str)
endPtlength<-length(dnaStr$x)
endPt1<-endPtlength/3
###################################################################
#The following code ensures that DNA is plotted in a cube
maxX<-max(dnaStr$x)
minX<-min(dnaStr$x)
minY<-min(dnaStr$y)
maxY<-max(dnaStr$y)
minZ<-min(dnaStr$z)
maxZ<-max(dnaStr$z)
difX<-abs(maxX-minX)
difY<-abs(maxY-minY)
difZ<-abs(maxZ-minZ)
angStrong<-round(max(difX,difY,difZ))
angStrongX<-(angStrong-difX)/2
angStrongY<-(angStrong-difY)/2
angStrongZ<-(angStrong-difZ)/2
minX<-minX-angStrongX
maxX<-maxX+angStrongX
minY<-minY-angStrongY
maxY<-maxY+angStrongY
minZ<-minZ-angStrongZ
maxZ<-maxZ+angStrongZ
###################################################################
#Plotting using rgl
###################################################################
#I would like to plot the following line using circles that are not filled

plot3dOut<-plot3d(dnaStr$x[1:endPt1],dnaStr$y[1:endPt1],dnaStr$z[1:endPt1], col="black", size=3, box=FALSE, axes=FALSE, lty="o", 
                  xlim=c(minX,maxX), ylim=c(minY,maxY),zlim=c(minZ,maxZ), xlab="",ylab="",zlab="")


#I would like to plot the following lines using filled circles

points3d(dnaStr$x[(endPt1+1):(endPt1*2)],dnaStr$y[(endPt1+1):(endPt1*2)],dnaStr$z[(endPt1+1):(endPt1*2)], box=FALSE, col="black", axes=FALSE, size=3, pch=21)

#This is the center line, is it possible to put the sequence here using lty

lines3d(dnaStr$x[(endPt1*2+1):(endPtlength)],dnaStr$y[(endPt1*2+1):(endPtlength)],dnaStr$z[(endPt1*2+1):(endPtlength)], box=FALSE, col="black",axes=FALSE,size =1)



More information about the R-help mailing list