# [R] Help in Lattice!

Gabor Grothendieck ggrothendieck at gmail.com
Sat Dec 20 04:43:00 CET 2008

```Write a panel= function:

dataM <- structure(list(ID = c(1L, 1L, 1L, 1L, 45L, 46L, 46L, 46L, 46L
), Dose = c(0L, 0L, 0L, 0L, 30L, 30L, 30L, 30L, 30L), Visit = c(0.5,
1, 1.5, 2, 3, 0.5, 1, 1.5, 2), Value = c(-0.065802, 0.24085,
-0.22907, 0.24074, -0.81316, -0.20786, -0.29336, -0.55657, -0.21659
)), .Names = c("ID", "Dose", "Visit", "Value"), class = "data.frame",
row.names = c("1",
"2", "3", "4", "270", "271", "272", "273", "274"))

library(lattice)
library(grid)
xyplot(Value ~ Visit | factor(ID), data = dataM, typ = 'o', as.table = TRUE,
subscripts = TRUE, Dose = dataM\$Dose,
panel = function(x, y, subscripts, Dose, ...) {
panel.xyplot(x, y, ...)
grid.text(paste("Dose =", Dose[subscripts][1]), .15, .15,
gp = gpar(cex = 0.6))
}
)

On Fri, Dec 19, 2008 at 7:07 PM, Haoda Fu <fuhds at yahoo.com.cn> wrote:
> Hi -
>
> How can I add different notes in different panels?
>
> My data looks like
>
>     ID Dose  Visit  Value
> 1    1    0   0.5 -6.5802e-02
> 2    1    0   1.0  2.4085e-01
> 3    1    0   1.5 -2.2907e-01
> 4    1    0   2.0  2.4074e-01
> ...   ...  ...  ...  ...
> 270 45   30   3.0 -8.1316e-01
> 271 46   30   0.5 -2.0786e-01
> 272 46   30   1.0 -2.9336e-01
> 273 46   30   1.5 -5.5657e-01
> 274 46   30   2.0 -2.1659e-01
>
> I use
> xyplot(Value ~ Visit | factor(ID), data = dataM, typ = 'o',layout = c(3,3),as.table=TRUE);
>
> to plot each patient longitudinal observations.
> How can I add dose information to each panel? e.g., adding "Dose = 30"
>
> Best,
> Haoda
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

```