Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting size of the rgl device

Tags:

plot

r

save

latex

rgl

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)
like image 975
Jen Bohold Avatar asked Aug 05 '13 18:08

Jen Bohold


2 Answers

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 )
like image 70
IRTFM Avatar answered Sep 29 '22 03:09

IRTFM


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

like image 25
Annie Avatar answered Sep 29 '22 02:09

Annie