9

I have a problem with the fullscreen / non-fullscreen of my rgl device.

Currently I use R 3.00

I plot a persp3d plot (library rgl) into my device, it opens in a quite small window:

The R code:

persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=red,
        ticktype="detailed", xlab="", ylab="", zlab="",axes=FALSE)
axes3d(c('x--','z'))

axis3d(edge='y+-',at =c(1,500,1000,1500,2000,2320),
labels =rownames(fd)[c(1,500,1000,1500,2000,2320)])

Which looks like this:

sc

I now rotated it and saved the single png files to my drive. The problem is, that the png files are too small? I want to put them into one paper using LaTex and the \animategraphics command, but it is to pixely (not sharp).

If I click on the fullscreen icon in the rgl device, so that the R plot is larger, this does help and everything works. The problem is, that there is too much white space around it. With this white space above, below, left and right to it I cannot include it in LaTex, because it does not fit because of its big size (width, height). I have 200 png files, so manually removing the white space with paint is not a nice work.

The small pictures look like this:

sc11

The following happens, if you zoom in (this is, what LaTex does, when I put it into my paper, it increases the picture, screenshot is from my LaTex file. Same picture, a slightly different angle, but the problem stays the same):

sc22

You see that it looks pixely (not good). Also you can already see the problem with the large files with too much white space: The small picture with some white space above already destroys my title.

So how could I solve this problem? How can I tell R to use the fullscreen plots but without so much white space around it? When I click on fullscreen and save those pictures everything is fine, except the white space around it.

Here is the png file with too much white space around it (in this screenshot there is no white space below, but when I use the correct zoom it is there):

sc2

One further note: This is the R code I use to save the png- files:

M <- par3d("userMatrix")
movie3d( spin3d(rpm=3), duration=20,dir="C:/test/movie", clean=FALSE )
play3d( spin3d(rpm=3), duration=20)
Jen Bohold
  • 1,038
  • 2
  • 10
  • 17

4 Answers4

9

Use par3d(windowRect = c(20, 30, 800, 800))

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
Annie
  • 681
  • 7
  • 14
6

You can inspect the state of the RGL device with par3d. The "whitespace" is controlled by the "windowRect" values. There is an automatic increase in those values as the size of the display is increased;

> par3d("windowRect")
[1] 100 100 356 378
> par3d("windowRect")  # made the window have roughly 4 times the area
[1] 137   0 744 544

You can also specify what the corners of the windowRect will be.

?par3d

This should give you control that avoids both the "whitespace problem and the title overlap.

If you want to make the object larger in the viewing window, the rgl.viewpoint function can zoom. Smaller number make objects appear larger.

rgl.viewpoint(  zoom = .5 )
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • thanks for your anwer, but it does not help me. In the manual it says, that windowRect gives me "the left, top, right and bottom of the displayed window (in pixels)." I tried to set it to e.g. 5,5,5,5 (small values for small borders) with e.g. par3d("usersMatrix",windowRect=c(5,5,5,5)) but it does not work (no picture). It seems, that this is just giving me the size as if I would increase it with the mouse? So if I set larger numbers I have the same problem again. So this is not a solution, since I still have the white space? – Jen Bohold Aug 05 '13 at 19:35
  • 1
    There needs to be enough "whitespace" so that you can rotate an object. Unless the object is spherical, that means there will be some whitespace when the object is displayed in some viewing angles. You may need to export it to an image and edit if you want to remove all that whitespace. Try `par3d("windowRect"= c(0,0,1200,1200))`. I think the last two values need to be large. – IRTFM Aug 05 '13 at 19:55
  • thanks for your answer, but: The white space is not necessary for rotating? Even if there is no white space, it could still rotate, or say, a smaller white boarder (some small boarder would be ok). When I use par3d("windowRect"= c(161,23,876,691)) this gives the right size of the plot, but the problem is, that there is still too much space? If I reduce the numbers or change it, the plot itself (the size of the surface) also changes, so not only the white space is reduced but also the complete plot. Exporting it to png and manually removing the white space 200 times? – Jen Bohold Aug 06 '13 at 08:03
2

It was enough to set r3dDefaults:

r3dDefaults$windowRect <- c(0,50, 800, 800) 
plot3d(mdatapc, col=kmeanspc.cluster, size = 10)    
42n4
  • 1,292
  • 22
  • 26
1

I think using aspect3d() might also come in handy.

aspect3d(x=5, y=1 , z =1)
rgl.viewpoint(zoom = .5)
Jim
  • 51
  • 4