Question: Saving 3D plot from rgl as a pdf
gravatar for ApoorvaB
13 days ago by
United States
ApoorvaB200 wrote:

Hi everyone,

I made a 3D plot using RGL using the plot3d function. The data is from Diffusion map coordinates of a single cell RNASeq dataset. I tried using rgl.postscript() function to save the plot as a pdf. But there are way too many points and after rendering for nearly an hour, my R studio crashes. Is there an alternate method to save 3d plots from rgl as a pdf ?

Following is the code I used

plot3d(data2[1:3],type='s',box=FALSE,col=data2$color,radius = .001) 

And here are a few lines from my data

                               DM_1        DM_2         DM_3 var_cluster   color
AAACCTGCACTCTGTC-E15.5 -0.001392666 0.006624446  0.001566648           5 #CBD588
AAACCTGGTCTTCTCG-E15.5 -0.001593669 0.008024144 -0.003262486           2 #74D944
AAACCTGGTTCGCTAA-E15.5 -0.001607172 0.008415930 -0.005092944           2 #74D944
AAACGGGAGTGGTAGC-E15.5 -0.001114521 0.005403248  0.007797941           2 #74D944
AAACGGGCAGCTGCTG-E15.5 -0.001559912 0.008073420 -0.004305803           4 #C0717C    
AAACGGGCATGAGCGA-E15.5 -0.001534235 0.007919188 -0.003495660           2 #74D944


3dplot rgl • 114 views
ADD COMMENTlink modified 5 days ago • written 13 days ago by ApoorvaB200
gravatar for Chris Miller
13 days ago by
Chris Miller20k
Washington University in St. Louis, MO
Chris Miller20k wrote:

This function is an example of using rgl to render a 3d plot and spin it, taking periodic snapshots and assembling them into a gif:

It's been years since I wrote that, and the details are a bit fuzzy, but maybe it provides some useful ideas, since it's definitely creating raster images!

ADD COMMENTlink written 13 days ago by Chris Miller20k
gravatar for Alex Reynolds
13 days ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

I have some code here that basically uses the same two routines as your script to export PDF and it scales well (for me):

I have another script in there that rotates snaps every degree around a plane, to make an animated GIF. However, if rgl is crashing, then this wouldn't help much since you can't make a PDF.

How many points are you working with in your scatterplot?

If scale is the issue then I have some code in Python + R-like pandas routines that might work better. Let me know.

Another idea is to subsample your dataset, or map your points to clusters, and plot ovoid clusters in place of points. If you have so many points that rgl chokes, then throwing away some points at random (most of which could be hidden behind others anyway) will definitely help with scale issues and could still communicate the data.

ADD COMMENTlink written 13 days ago by Alex Reynolds28k
gravatar for ApoorvaB
5 days ago by
United States
ApoorvaB200 wrote:

Thank you. That was very helpful. I did manage to make a gif file. But what i really wanted was a 3D plot in the right orientation for a paper. So i needed a pdf. I used the plot3D package and got the results i was hoping for.

For anyone trying to do the same, you can use the links here and here.

ADD COMMENTlink written 5 days ago by ApoorvaB200
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1791 users visited in the last hour