Skip to content

Lattice: problem with setting space between plot and legend

6 messages · mike1989, Raphael Saldanha, Bert Gunter +2 more

#
Dear R Users, 

I am writing code to present my output data (I'm using Lattice Package).
However, it's essential for me to control space between barchart and legend.
I've read the package's specification, but unfortunately I haven't spot the
information how to do this. Here's the code I've written:

barchart(mymatrix[,1:ncol(mymatrix)],horizontal=FALSE, 
box.width=1,stack=TRUE,border=FALSE,par.settings = simpleTheme(col
=my_colors),lty="dotted",lend="butt",key=list(space="bottom",columns=ncol(mymatrix),points=FALSE,text=list(colnames(mymatrix)),rectangles=list(border=FALSE,size=2,col=my_colors[1:ncol(mymatrix)]),border=FALSE,rows=1,between=0.25))


Thank you for any assistance. 

--
View this message in context: http://r.789695.n4.nabble.com/Lattice-problem-with-setting-space-between-plot-and-legend-tp3749919p3749919.html
Sent from the R help mailing list archive at Nabble.com.
#
On Aug 17, 2011, at 9:15 AM, mike1989 wrote:

            
require(lattice)
a) You ought to use spaces and linefeeds for readability
b) It appears you are using the key option so the documentation is in  
the .../key section regarding placement:

"Alternatively, [and this comes just after the description of the  
space= options] the key can be positioned inside the plot region by  
specifying components x, y and corner. x and y determine the location  
of the corner of the key given by corner, which is usually one of  
c(0,0), c(1,0), c(1,1) and c(0,1), which denote the corners of the  
unit square. Fractional values are also allowed, in which case xand y  
determine the position of an arbitrary point inside (or outside for  
values outside the unit interval) the key."

Now I will admit that I did not understand what that last sentence  
regarding an "arbitrary point inside the key" might mean on the first  
three readings. I'm hoping it means a "user-determined point inside  
the _plot_". I also cannot figure out from that paragraph or the one  
that follows which corner of the key is being located.

Lack of an included example triggers my do-no-more rule regarding such  
posts.
#
(Note: Posted at the suggetsion of David Winsemius, to whom I already
sent a private reply).

Inline Below.
On Wed, Aug 17, 2011 at 7:34 AM, David Winsemius <dwinsemius at comcast.net> wrote:
I don't think so. Here's my translation of the Help file:

There are 2 coordinate systems at play here, that of the plot and that
of the key. The plot's coordinate system is native, and is used by the
x and y components of the space component of key. The key's coordinate
system is 0 to 1 on both axes and specifies the key coordinate that is
placed at the x and y plot location. Hence, space = list (x=10, y =
2,corner = c(1,0)) says "place the right lower corner of the key at
plot location (10,2).  Replacing the corner component by c(.5,.5)
means "place the center of the key at that location on the plot."

Cheers,
Bert
#
On Aug 17, 2011, at 11:19 AM, Bert Gunter wrote:

            
Thanks, Bert;

That did clarify for me that the x and y arguments were specifying the  
plot coordinates (expressed in data variable units) of a particular  
point of the key box (specified in unit key-coordinates). Thanks for  
lessening my overall confusion.
#
Hi

If space="bottom" then I think that par.settings needs to be utilized

?xyplot
search for par.settings
names(trellis.par.get())
trellis.par.get()[[28]]
layout heights may be needed

  names(trellis.par.get()[[28]])
  [1] 
"top.padding"       "main"              "main.key.padding"  "key.top" 
           "xlab.top"          "key.axis.padding"
  [7] 
"axis.top"          "strip"             "panel" 
"axis.panel"        "between"           "axis.bottom"
[13] "axis.xlab.padding" 
"xlab"              "xlab.key.padding"  "key.bottom" 
"key.sub.padding"   "sub"
[19] "bottom.padding"

therefore one scenario is to add the argument to barchart eg to increase space

par.settings = list(layout.heights = list(key.top = 2)),

also bottom.padding etc depending on the requirements other arguments 
to layout heights may be necessary.

The request was not specific enough to elaborate.

HTH

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email: home mackay at northnet.com.au
At 23:56 17/08/2011, you wrote: