Kjetil Halvorsen
2009-Nov-26 19:43 UTC
[R] lattice --- different properties of lines corresponding to type=c("l", "a") respectively
I think the subject says it all. I want to make a simple lattice plot,
using xyplot with the
argument type=c("l","a").
The problem then is that in the resulting plot it is
difficult/impossible to see which plot corresponds to the average
and which to the individual profiles. I triedthings like extra
arguments lwd=c(1,3) or col=c("blue","red")
hoping this would be interpreteded parallely to the type= argument,
but no. Like:
xyplot(response ~ time|group, repa0, groups=~Participant, type=c("b",
"a"), lwd=c(1, 3),
ylim=c(0, 10))
and many other variants ...
Then I vent for writing my own panel functions:
mypanel <- function(x, y, ..., type){
panel.average(x, y, ..., horizontal=FALSE)
panel.xyplot(x, y, ..., type=type)
}
xyplot(response ~ time|group, repa0, groups=~Participant, type="l",
ylim=c(0, 10),
panel=panel.superpose, panel.groups=mypanel)
(which doesn't work)
???
Kjetil Halvorsen
To recreate the data:
repa0 <-
structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 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 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), response = c(2L,
10L, 8L, 4L, 0L, 4L, 10L, 2L, 3L, 4L, 1L, 2L, 3L, 3L, 5L,
2L, 10L, 3L, 0L, 3L, 10L, 1L, 7L, 3L, 2L, 10L, 8L, 5L, 8L,
0L, 10L, 2L, 0L, 2L, 10L, 10L, 3L, 2L, 10L, 4L, 6L, 0L, 5L,
0L, 6L, 2L, 0L, 2L, 10L, 5L, 3L, 2L, 6L, 4L, 5L, 0L, 5L,
0L, 5L, 0L, 0L, 0L, 10L, 0L, 0L, 2L, 5L, 0L, 5L, 0L, 3L,
8L, 6L, 1L, 3L, 0L, 5L, 4L, 10L, 0L, 3L, 3L, 6L, 5L, 2L,
0L, 2L, 0L, 4L, 0L, 5L, 4L, 5L, 1L, 0L, 2L, 0L, 5L, 3L, 1L,
8L, 2L, 4L, 0L, 0L, 0L, 10L, 4L, 3L, 0L, 0L, 10L, 3L, 3L,
6L, 1L, 4L, 0L, 0L, 0L, 10L, 3L, 3L, 2L, 2L, 10L, 2L, 3L,
5L, 0L, 1L, 0L, 0L, 0L, 10L, 2L, 3L, 2L, 0L, 6L)), .Names =
c("group",
"Participant", "time", "response"), row.names =
c("1.1", "2.1",
"3.1", "4.1", "5.1", "6.1",
"7.1", "8.1", "9.1", "10.1",
"11.1",
"12.1", "13.1", "14.1", "1.2",
"2.2", "3.2", "4.2", "5.2",
"6.2",
"7.2", "8.2", "9.2", "10.2",
"11.2", "12.2", "13.2", "14.2",
"1.3", "2.3", "3.3", "4.3",
"5.3", "6.3", "7.3", "8.3",
"9.3",
"10.3", "11.3", "12.3", "13.3",
"14.3", "1.4", "2.4", "3.4",
"4.4", "5.4", "6.4", "7.4",
"8.4", "9.4", "10.4", "11.4",
"12.4",
"13.4", "14.4", "1.5", "2.5",
"3.5", "4.5", "5.5", "6.5",
"7.5",
"8.5", "9.5", "10.5", "11.5",
"12.5", "13.5", "14.5", "1.11",
"2.11", "3.11", "4.11", "5.11",
"6.11", "7.11", "8.11", "9.11",
"10.11", "11.11", "12.11", "13.11",
"14.11", "1.21", "2.21",
"3.21", "4.21", "5.21", "6.21",
"7.21", "8.21", "9.21", "10.21",
"11.21", "12.21", "13.21", "14.21",
"1.31", "2.31", "3.31", "4.31",
"5.31", "6.31", "7.31", "8.31",
"9.31", "10.31", "11.31", "12.31",
"13.31", "14.31", "1.41", "2.41",
"3.41", "4.41", "5.41", "6.41",
"7.41", "8.41", "9.41", "10.41",
"11.41", "12.41", "13.41", "14.41",
"1.51", "2.51", "3.51", "4.51",
"5.51", "6.51", "7.51", "8.51",
"9.51", "10.51", "11.51", "12.51",
"13.51", "14.51"), class = "data.frame")
Deepayan Sarkar
2009-Nov-27 11:50 UTC
[R] lattice --- different properties of lines corresponding to type=c("l", "a") respectively
On Fri, Nov 27, 2009 at 1:13 AM, Kjetil Halvorsen <kjetilbrinchmannhalvorsen at gmail.com> wrote:> I think the subject says it all. I want to make a simple lattice plot, > using xyplot with the > argument ? ? type=c("l","a"). > The problem then is that in the resulting plot it is > difficult/impossible to see which plot corresponds to the average > and which to the individual profiles. I triedthings like extra > arguments ?lwd=c(1,3) ? or ? col=c("blue","red") > hoping this would be interpreteded parallely to the type= ?argument, > but no. ?Like: > > xyplot(response ~ time|group, repa0, groups=~Participant, type=c("b", > "a"), lwd=c(1, 3), > ? ? ? ylim=c(0, 10))Are you looking for per-group average or overall average? All your attempts will do per-group average, which is rather pointless here. For a global average you need to call panel.average with all the data, not through panel.superpose: mypanel <- function(x, y, ..., groups, type){ panel.xyplot(x, y, ..., groups = groups, type=type) panel.average(x, y, horizontal = FALSE, col = "black", lwd = 3) } xyplot(response ~ time|group, repa0, groups=~Participant, type="l", ylim=c(0, 10), panel=mypanel) -Deepayan> > and many other variants ... > > Then I vent for writing my own panel functions: > mypanel <- function(x, y, ..., type){ > ? ?panel.average(x, y, ..., ?horizontal=FALSE) > ? ?panel.xyplot(x, y, ..., type=type) > ?} > xyplot(response ~ time|group, repa0, groups=~Participant, type="l", > ylim=c(0, 10), > ? ? ? panel=panel.superpose, panel.groups=mypanel) > > (which doesn't work) > ??? > Kjetil Halvorsen > To recreate the data: > > repa0 <- > structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), > ? ?Participant = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, > ? ?11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, > ? ?11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, > ? ?11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, > ? ?11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 2L, 3L, 3L, 5L, > ? ?2L, 10L, 3L, 0L, 3L, 10L, 1L, 7L, 3L, 2L, 10L, 8L, 5L, 8L, > ? ?0L, 10L, 2L, 0L, 2L, 10L, 10L, 3L, 2L, 10L, 4L, 6L, 0L, 5L, > ? ?0L, 6L, 2L, 0L, 2L, 10L, 5L, 3L, 2L, 6L, 4L, 5L, 0L, 5L, > ? ?0L, 5L, 0L, 0L, 0L, 10L, 0L, 0L, 2L, 5L, 0L, 5L, 0L, 3L, > ? ?8L, 6L, 1L, 3L, 0L, 5L, 4L, 10L, 0L, 3L, 3L, 6L, 5L, 2L, > ? ?0L, 2L, 0L, 4L, 0L, 5L, 4L, 5L, 1L, 0L, 2L, 0L, 5L, 3L, 1L, > ? ?8L, 2L, 4L, 0L, 0L, 0L, 10L, 4L, 3L, 0L, 0L, 10L, 3L, 3L, > ? ?6L, 1L, 4L, 0L, 0L, 0L, 10L, 3L, 3L, 2L, 2L, 10L, 2L, 3L, > ? ?5L, 0L, 1L, 0L, 0L, 0L, 10L, 2L, 3L, 2L, 0L, 6L)), .Names = c("group", > "Participant", "time", "response"), row.names = c("1.1", "2.1", > "3.1", "4.1", "5.1", "6.1", "7.1", "8.1", "9.1", "10.1", "11.1", > "12.1", "13.1", "14.1", "1.2", "2.2", "3.2", "4.2", "5.2", "6.2", > "7.2", "8.2", "9.2", "10.2", "11.2", "12.2", "13.2", "14.2", > "1.3", "2.3", "3.3", "4.3", "5.3", "6.3", "7.3", "8.3", "9.3", > "10.3", "11.3", "12.3", "13.3", "14.3", "1.4", "2.4", "3.4", > "4.4", "5.4", "6.4", "7.4", "8.4", "9.4", "10.4", "11.4", "12.4", > "13.4", "14.4", "1.5", "2.5", "3.5", "4.5", "5.5", "6.5", "7.5", > "8.5", "9.5", "10.5", "11.5", "12.5", "13.5", "14.5", "1.11", > "2.11", "3.11", "4.11", "5.11", "6.11", "7.11", "8.11", "9.11", > "10.11", "11.11", "12.11", "13.11", "14.11", "1.21", "2.21", > "3.21", "4.21", "5.21", "6.21", "7.21", "8.21", "9.21", "10.21", > "11.21", "12.21", "13.21", "14.21", "1.31", "2.31", "3.31", "4.31", > "5.31", "6.31", "7.31", "8.31", "9.31", "10.31", "11.31", "12.31", > "13.31", "14.31", "1.41", "2.41", "3.41", "4.41", "5.41", "6.41", > "7.41", "8.41", "9.41", "10.41", "11.41", "12.41", "13.41", "14.41", > "1.51", "2.51", "3.51", "4.51", "5.51", "6.51", "7.51", "8.51", > "9.51", "10.51", "11.51", "12.51", "13.51", "14.51"), class = "data.frame") > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >