3

How to increase resolution of gif image generated by rgl package of R (plot3d and movie3d functions) - either externally or through R ?

R Code :

MyX<-rnorm(10,5,1)
MyY<-rnorm(10,5,1)
MyZ<-rnorm(10,5,1)
plot3d(MyX, MyY, MyZ, xlab="X", ylab="Y", zlab="Z", type="s", box=T, axes=F)
text3d(MyX, MyY, MyZ, text=c(1:10), cex=5, adj=1)
movie3d(spin3d(axis = c(0, 0, 1), rpm = 4), duration=15, movie="TestMovie",
                                                type="gif", dir=("~/Desktop"))

Output :

Output Update

Adding this line at the beginning of code solved the problem

r3dDefaults$windowRect <- c(0, 100, 1400, 1400) 
Mike Wise
  • 22,131
  • 8
  • 81
  • 104
384X21
  • 6,553
  • 3
  • 17
  • 17
  • 1
    You mean you want to change the width & height of the image? I ask because I am not sure to understand what you mean by resolution of an image. I use this term for my computer display.. – agstudy Jan 23 '13 at 12:36
  • Yes but without loosing quality. Tried [gifsicle](http://manpages.ubuntu.com/manpages/natty/man1/gifsicle.1.html). I loose quality with gifsicle – 384X21 Jan 23 '13 at 12:39
  • 2
    `movie3D` uses Image Magick. You can use the function's `convert` parameter to fine tune this. See the help file. – Roland Jan 23 '13 at 13:07

1 Answers1

4

I don't think you can do much about the resolution of the gif itself. I think you have to make the image much larger as an alternative, and then when you display it smaller it looks better. This is untested as a recent upgrade broke a thing or two for me, but this did work under 2.15:

par3d(windowRect = c(0, 0, 500, 500)) # make the window large
par3d(zoom = 1.1) # larger values make the image smaller

# you can test your settings interactively at this point

M <- par3d("userMatrix") # save your settings to pass to the movie

movie3d(par3dinterp(userMatrix=list(M,
    rotate3d(M, pi, 1, 0, 0), 
    rotate3d(M, pi, 0, 1, 0) ) ), 
    duration = 5, fps = 50,
    movie = "MyMovie")

HTH. If it doesn't quite work for you, check out the functions used and tune up the settings.

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
  • I read about changing window size in R-help forum. Tried it. I get the following error (reported by others elsewhere, might be broken as you said): Error in par3d(windowRect = c(0, 0, 500, 500)) : unknown error getting rgl parameter "windowRect". BTW I use R 2.12 and rgl 0.92.794 – 384X21 Jan 23 '13 at 12:45
  • Are you on Mac or Windows? On the Mac, there is a rogue file often left from earlier installs that causes these kinds of problems, and must be found and removed. If you are on Mac, try googling your error and see if you can find the instructions (it's been a while since I fixed mine and don't quite remember - also check the main help archives). – Bryan Hanson Jan 23 '13 at 12:50
  • I'm on Linux. Will check if updating packages will help. Thx – 384X21 Jan 23 '13 at 12:52
  • Check around... Macs run linux, so maybe the problem is the same.... See the accepted answer here: http://stackoverflow.com/questions/9878693/error-in-loading-rgl-package-with-mac-os-x But this looks very Mac specific, unless your system uses X11 windows. You could also try building from source. – Bryan Hanson Jan 23 '13 at 12:58
  • @BryanHanson you've opened up a flame war :-). Macs do not run Linux -- they run Darwin, which is a Unix-based kernel. – Carl Witthoft Jan 23 '13 at 14:05
  • @CarlWitthoft I guess that's OK, it's 10 F here and we could use the heat! – Bryan Hanson Jan 23 '13 at 14:19