Skip to content

Setting the width and height of a Sweave figure

2 messages · Henrik Andersson, Bjørn-Helge Mevik

#
Hello R-people,

I have a function which plots two figures next to each other
using  if(dev.cur()==1) x11(width=14,height=7) to create a new window 
and set the size of the window automatically if no device is open.

This works fine in interactive mode but I don't know how Sweave gets the 
parameters for the figures, and right now the default behavior causes 
this figure to be square and the subfigures becomes not no square, 
making them look silly.

I want a general solution so my function can be used in both interactive 
mode and in a sweave file.

Thanks, Henrik Andersson

---------------------------------------------------------
<<>>=
myfun <- function(){
if(dev.cur()==1) x11(width=14,height=7)
par(mfrow=c(1,2))
plot(1:5)
plot(1:5)
}

<<fig=TRUE>>=
myfun()


---------------------------------------------
Henrik Andersson
Netherlands Institute of Ecology -
Centre for Estuarine and Marine Ecology
P.O. Box 140
4400 AC Yerseke
Phone: +31 113 577473
h.andersson at nioo.knaw.nl
http://www.nioo.knaw.nl/ppages/handersson
4 days later
#
I haven't found any other solution than using

<<fig=TRUE,height=7,width=14>>
theCode()
@

(but of course that doesn't have any effect when theCode() is used
interactively).