Skip to content
Prev 261628 / 398502 Next

lattice panel fine control

Hi:

See inline.
On Wed, Jun 1, 2011 at 10:00 AM, maxbre <mbressan at arpa.veneto.it> wrote:
You forgot to plot the points in the panel function; you needed to add
panel.xyplot(x, y, ...). panel.abline() is not getting rid of the
points - you never indicated that you wanted them plotted.
One way is with panel.text(); see below. Another option is to use the
directlabels package, which has better algorithms for positioning text
relative to points.
I have no clue what you mean by this; are you referring to error bar
plots in the margins of each scatterplot? If so, that's not easy to do
since AFAIK there's no panel.errorbar() function. If this is what you
mean, you may have to write a panel function to add that functionality
to an xyplot; since you want different scales in each panel, the panel
function would have to be sensitive to scaling, which means you would
need to pay attention to the units in which you'd be plotting. If
you're lucky, someone may help you out with that.

Rug plots or density strips might be less intrusive than error bar
plots; for the latter, see the denstrip package. For rug plots, see
panel.rug(). IIRC, the denstrip package has a panel function for use
in lattice. These aren't necessarily better than error bar plots, but
they are alternatives that are useful to know about.
See the example code below. The log base is specified in the scales()
statement for each of x and y; in particular, TRUE is replaced with 10
in each case. One then uses the *scales.component.logpower function
from latticeExtra to do the work, where * is either x or y.
Sans the error bar plots, this seems to be close to what you wanted:

myplot<-xyplot(ped.avg ~ tv.avg | family,
               data=mydata,
               strip=strip.custom(bg='white'), col.line=1, main="title",
               xlab="tv [fg/m3]", ylab="ped [fg/m3]",
               scales= list(x=list(relation="free", log=10),
                            y=list(relation="free", log=10)),
               prepanel = function(x, y, ...) {
                  xlim=list(c(1.9,3), c(2,3.8), c(0.5,2.7), c(1.2, 2.4))
                  ylim=list(c(1.9,3), c(2,3.8), c(0.5,2.7), c(1.2, 2.4))
                 },
               panel = function(x, y, ...) {
                  panel.xyplot(x, y, ...)
                  panel.abline(a = 0, b = 1, lty = 1, col = 1)
                  panel.text(x, y, lab = mydata$name, cex = 0.6)
                 },
               xscale.components = xscale.components.logpower,
               yscale.components = yscale.components.logpower
    )

The prepanel function sets the xlim and ylim values for each panel.
The panel function plots the points, the 45 degree line and the text
labels, although the points are rather superfluous because they are
overwritten by the labels. Notice that by changing the limits, the 45
degree lines no longer bisect each panel.

If your m3 is really supposed to be m^3 (as in cubic meters), then you
can use expressions to do the work; one way is to replace your xlab
and ylab in the above call with

xlab = expression(paste('tv [fg/', m^3, ']', sep = '')),
ylab= expression(paste('ped [fg/', m^3, ']', sep = '')),

If you want to get rid of the points, take the panel.xyplot() line out
of the panel function (or comment it out).

HTH,
Dennis