Saving 3D plot from rgl as a pdf
3
0
Entering edit mode
5.0 years ago
AB ▴ 360

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) 
rgl.postscript("plot.pdf",fmt="pdf")

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

Thanks

rgl 3dplot • 8.2k views
ADD COMMENT
1
Entering edit mode
5.0 years ago

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:

https://github.com/genome/sciclone/blob/master/R/plots.R#L1171

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 COMMENT
1
Entering edit mode
5.0 years ago

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

https://github.com/alexpreynolds/cubemaker/blob/gh-pages/cubemaker-viz-proxy/convert_model_mtx_to_pdf_via_rgl.Rscript

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 plot.ly 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 COMMENT
1
Entering edit mode
5.0 years ago
AB ▴ 360

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 COMMENT

Login before adding your answer.

Traffic: 1923 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6