Evan Cooch
2015-Feb-09 00:41 UTC
[R] specifying dimensions of a graphic (not the window...)
Greetings --
Graphics newbie (I generally don't use R for graphics, so if the
question is 'obvious', point that out gently ;-)
I'm trying to use levelplot in the lattice package, to generate what
I'll call a 'decision table', where optimal decisions (discrete, on
the
interval [0.0,0.5] by increments of 0.1) from a dynamic programming
problem are plotted as a function of time since the time horizon. The
'matrix' I'm trying to plot is 100 rows x 10 columns. While using
the
following works, more or less...
rgb.palette <- colorRampPalette(c("red", "green"), space
= "rgb")
levelplot(t(results$policy), main="optimal harvest", xlab="time
from
end", ylab="state (N)", col.regions=rgb.palette(6), cuts=6,
at=seq(0,0.5,0.1))
the rendered figure is waaaaay too narrow. I want to make the
proportions of the 'levelplot' (what I usually call a 'heat
map') square
(or something else that I specify). I'm used to dedicated graphics
applications wherew I simply grab the figure and resize it to whatever
aspect ratio I want. Obviously, with R, I need to invoke some sort of
command line argument.
In my searches, I've found a fair number of queries/answers about how to
change the size of the graphics windows, but I could care lerss what the
graphics window sizing is (presumably, it should adjust to whatever the
size of the underlying graphic is). I want to 'hard code' the dimensions
of the graphic itself, not the window it's rendered in.
I'm sure the answer is out there, but I've been unsuccessful at finding
the magic keywords in my searches.
Thanks in advance.
[[alternative HTML version deleted]]
Evan Cooch
2015-Feb-09 01:13 UTC
[R] specifying dimensions of a graphic (not the window...)
On 2/8/2015 7:41 PM, Evan Cooch wrote:> Greetings -- > > Graphics newbie (I generally don't use R for graphics, so if the > question is 'obvious', point that out gently ;-) > > I'm trying to use levelplot in the lattice package, to generate what > I'll call a 'decision table', where optimal decisions (discrete, on > the interval [0.0,0.5] by increments of 0.1) from a dynamic > programming problem are plotted as a function of time since the time > horizon. The 'matrix' I'm trying to plot is 100 rows x 10 columns. > While using the following works, more or less... > > rgb.palette <- colorRampPalette(c("red", "green"), space = "rgb") > levelplot(t(results$policy), main="optimal harvest", xlab="time from > end", ylab="state (N)", col.regions=rgb.palette(6), cuts=6, > at=seq(0,0.5,0.1)) > >Sufficient solution to the problem for now -- adding the option aspect="fill" fills the window, and if I specify the size of the window, then this amounts to the same thing, more or less. Seems kind of a backward way to do it. I'd have thought setting size of the graphic, and then having the window size change dynamically around said graphic, would have been more intuitive. [[alternative HTML version deleted]]