[R] Additions to xyplot (lattice)? - legend, ticks, axis label size, text

deepayan.sarkar at gmail.com deepayan.sarkar at gmail.com
Thu Aug 30 20:12:22 CEST 2007


On 8/30/07, Dave Hewitt <dhewitt at vims.edu> wrote:
> I have created an xyplot of a time series with the following code...
>
> win.graph(width = 10, height = 7)
>
> panel1 = function(x, y)  {
>       panel.loess(x, y, lwd=2.5, span=0.5, col="gray")
>       panel.xyplot(x, y, pch=19, col="blue", cex=1.25)
>       }
>
> xyplot(oneplusdensity ~ year, data=figdata, aspect="fill", cex=1.5,
>       xlab=NULL, ylab=expression("Crabs per 1,000 m"^2),
>       xlim=c(1964, 2007), ylim=c(-2, 62),
>       scales=list (x=list(tick.number=41, cex=0.8, rot=90),
>       y= list(tick.number=7, cex=1.2)), panel=panel1)
>
> I want to do the following things:
>
> (1) Remove the ticks on the top and right boundaries

scales = list(tck = c(1, 0), x = ..., y = ...)

> (2) Increase the size of the y-axis label to be larger than the tick labels

ylab = list( expression(...), cex = 2)

> (3) Add a legend with the points and lowess line

See the entry for 'key' in ?xyplot. As a starting point,

key = list(text = list("loess"), lines = list(lwd=2.5, span=0.5, col="gray"),
           text = list("points"), points = list(pch=19, col="blue", cex=1.25))

> (4) Add some annotation (text) in the lower left corner ('text' for plot()
> did not work)

Use panel.text() instead inside your panel function.

-Deepayan

> I'm relatively new to lattice and spent a few hours with the manual and
> other help pages. I've begun to wonder if a regular old plot() for this
> would be better. Appreciate any redirection or suggestions.



More information about the R-help mailing list