xyplot (lattice), strip.default
Wladimir Eremeev wrote:
Dear r-help,
I've got data of the following structure
1979 93.428747 0
1979 87.298608 20
1979 78.506340 40
...
1979 45.567890 340
1980 60.815289 0
1980 49.630904 20
1980 24.981362 40
...
The first column is year and the last one is the longitude.
I need a set of graphs showing the dependence of the middle value on
the longitude, for each year, situated one blow the other.
I.e.
1979: --...---```--``--..
1980: ...--``../``\...---
...
etc.
Here characters ---...---``` denote the curve.
The middle value is on the vertical axis
and the latitude is on the horizontal axis of each graph.
To do this I use xyplot function from the Lattice package:
xyplot(ac15$"value"~ac15$lon|year,data=ac15,
type="l",
layout=c(1,24),
xlab="Longitude",
as.table=TRUE,
bg="white"
);
But I have some problems using it.
Questions:
1. How to make xyplot to draw the year value in the strip above each
graph instead of writing the word 'year'?
Look at ?strip.default and try style = 4, or style = 5:
fooData <- data.frame(
year = factor(rep(2001:2010, each = 20)),
y = rnorm(200),
x = rep(1:20, time = 10))
library(lattice)
trellis.device(bg = "white")
xyplot(y ~ x | year, data = fooData,
type = "l",
layout = c(1, 10),
xlab = "Longitude",
as.table = TRUE,
strip = function(...) strip.default(style = 5,...)
)
2. I'd like to produce a .png file with graphs without drawing them on the screen.
Look at ?trellis.device:
trellis.device(bg = "white",
device = "png",
filename = "d:/analyses/fig1.png")
xyplot(y ~ x | year, data = fooData,
type = "l",
layout = c(1, 10),
xlab = "Longitude",
as.table = TRUE,
strip = function(...) strip.default(style = 5,...)
)
dev.off()
Best,
Renaud
I try:
png(filename = "Rplot.png", width = 480, height = 1024, pointsize = 12,
bg = "white");
trellis.device(device=getOption("png"),
color = FALSE,
bg = "white" );
xyplot.... [see above]
But I get the error message:
Error in trellis.device(device = getOption("png"), color = FALSE, bg = "white") :
couldn't find function "device.call"
Where's the problem?
I use R 1.7.0 and Windows NT 4.0 workstation.
Thank you for attention and help!
Dr Renaud Lancelot, v?t?rinaire CIRAD, D?partement Elevage et M?decine V?t?rinaire (CIRAD-Emvt) Programme Productions Animales http://www.cirad.fr/fr/pg_recherche/page.php?id=14 ISRA-LNERV tel +221 832 49 02 BP 2057 Dakar-Hann fax +221 821 18 79 (CIRAD) Senegal e-mail renaud.lancelot at cirad.fr