3

From @DWin and @Ben Bolker, we can change the scatter3d function in R to plot "prettier" (http://stackoverflow.com/questions/8204972/carscatter3d-in-r-labeling-axis-better), however, saving the plot is a trickier. rgl.snapshot saves the image as a png but to save a high resolution image (PDF) rgl.postscript must be used. Using rgl.postscript will not save the image with font/text size/axis sizes as specified (I edited the scatter3d function to increase text/axis sizes). rgl.snapshot works as it should so why doesn't rgl.postscript? Does anyone know an alternative saving method or is there a way to save the plot with larger text/axis etc?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Megan
  • 195
  • 1
  • 14
  • 1
    Can you try installing the r-forge version (`install.packages("rgl",repos="http://r-forge.r-project.org") and see if that makes a difference? The log at https://r-forge.r-project.org/scm/viewvc.php/pkg/?root=rgl&view=log says: `Revision 828 - Directory Listing; Modified Mon Jun 6 17:19:04 2011 UTC (6 months, 3 weeks ago) by murdoch; Respect font size in rgl.postscript calls`, and the change might (?) not have propagated to the CRAN version ... – Ben Bolker Jan 02 '12 at 15:22
  • yes, this is very helpful however, i believe it only works on windows or I could only get it functioning correctly on windows. – Megan Jan 05 '12 at 20:50
  • that's funny. I didn't try it on Windows, only on Linux (I could try it on a Mac if that would be helpful) – Ben Bolker Jan 05 '12 at 21:25
  • No its ok, i switched to a windows machine, thanks though – Megan Jan 05 '12 at 21:34

1 Answers1

1

A simple example works for me with the a more recent version of rgl than the CRAN one (CRAN has 0.92.798, r-forge now has 0.92.836, this is with 0.92.829). It looks like versions are numbered by SVN revision, so this is one version after the update mentioned in the comments above ...

library(rgl)
set.seed(1001)
n <- 20
text3d(runif(n),runif(n),runif(n),LETTERS[1:n],cex=seq(0.5,5,length=n))
rgl.postscript(file="tmp.ps")

However, a big warning is that the resulting PS, PDF, files etc. are a bit wonky. The bounding boxes are a little odd, although I could text-edit that manually. ps2pdf and ps2png mangled it .. epstopdf seems to have worked (these are all tools that are available on Linux boxes, don't know about for other OS). In principle rgl.postscript() allows you to export as PDF, but it might be weird PDF ... StackOverflow doesn't recognize the file as being in a valid upload format.

R Under development (unstable) (2012-01-01 r58032)
Platform: i686-pc-linux-gnu (32-bit)

[snip]

other attached packages:
[1] rgl_0.92.829

enter image description here

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thanks for the wizardry! I've been struggling to get this to work correctly and I'm very close. To make a scatter3d plot, i had to make the plot and then add: mtext3d, axes3d and axis3d. Ironically, I found using rgl.postscript and saving it as a pdf worked best and it was the the ps files that came out wonky. I am now struggling to make the size of the points larger. I tried to use plot3d/points3d and adding it to the original plot but that failed. Any suggestions? – Megan Jan 05 '12 at 21:02
  • Hmm. `plot3d(1:5,1:5,1:5,size=20)` gives big ugly squares for me. `spheres3d(1:5,1:5,1:5,radius=0.3)` gives nice shiny spheres (you wouldn't want to use spheres if you had thousands of points to plot, they're computationally intensive compared to the ugly squares). – Ben Bolker Jan 05 '12 at 21:40
  • It's unfortunate the edited version of the scatter3d function on your website will not work for me (text size/point size) when I save it as a pdf. – Megan Jan 09 '12 at 14:54
  • the best way that I found to make a higher quality scatter3d image, is editting the scatter3d function and using image magic to convert between image types. ie. convert -size 8x8 -pointsize 72 -resample 300 -sharpen 300x100 filename.png filename.tiff. woohoo – Megan Jan 25 '12 at 16:41