Skip to content

Shrink Trellis margins settings (when printed to png file)

2 messages · Mark Heckmann, Deepayan Sarkar

#
Dear R-experts,

I have two problems:

PROBLEM (1)
-----------

I want to produce a very small png file (35 x 18 px) that contains a
histogram without a figure region or margins, only the pure heights. 
In the base graphic system this is simple:

  png(filename = "hist.png", res = 72, width=35, height=18)
        par(mar=c(0,0,0,0), oma=c(0,0,0,0))
        hist(rnorm(100), main="")
  dev.off()

Now I want a grid graphics output as I need the graphic as an object.
I tried several trellis.par settings but I was not able to figure it out
(PROBLEM (1)).

Up to now it looks like this:

library(lattice)
histogram(rnorm(100), xlab="", ylab="", 
                     	 par.settings=list(
axis.line=list(col="transparent"),
xlab.text=list(col="transparent"),
ylab.text=list(col="transparent"),
	
axis.text=list(col="transparent"))
 )

This looks acceptable although I would like smaller margins, that is to say
no margins at all. How cab I achieve that?



PROBLEM (2) 
-----------
Now is, that when it is printed to the png file, the graphic almost consist
of margins only. The main part of the plot shrinks to some tiny points.

I don't know how to change the settings, so I that I get the same as in the
base system.

Does anyone know?


TIA
Mark
#
On Wed, Dec 17, 2008 at 8:11 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote:
You could do it this way if you really want, but a better approach
would be to directly plot the pieces you want (rather than start with
a high-level solution and get rid of the pieces you don't want). For
example:


library(lattice)
library(grid)

x <- rnorm(100)
limits <- prepanel.default.histogram(x, breaks = NULL)
## grid.newpage() # to start a new page
pushViewport(viewport(xscale = extendrange(limits$xlim),
                      yscale = extendrange(limits$ylim)))
panel.histogram(x, breaks = NULL)


-Deepayan