[R] xyplot of function only shows diagonal plots
Deepayan Sarkar
deepayan.sarkar at gmail.com
Wed Jul 7 22:50:44 CEST 2010
On Wed, Jul 7, 2010 at 12:17 PM, DrHatch <DrHatch at patandhatch.org> wrote:
> I expected this script to show nine panels, each with a plot of the
> function.
> But when I run it, only the diagonal panels have content.
> Executing > print(trel_1) shows what I expected in the upper left corner.
> I am using R ver. 2.11.0 and lattice ver. 0.18-8 on Windows XP under Eclipse
> and StatET.
> I have searched the documentation, but found no answer. What am I missing?
That you haven't created all the (a, b) combinations you want: you are
plotting these combinations
> cbind(a, b)
a b
[1,] 1 1
[2,] 2 2
[3,] 3 3
when you actually want these:
> expand.grid(a = a, b = b)
a b
1 1 1
2 2 1
3 3 1
4 1 2
5 2 2
6 3 2
7 1 3
8 2 3
9 3 3
-Deepayan
>
> --- simple.R ---
>
> # Test xyplot layout for a function
> #
> require("lattice")
>
> f <- function(x,a,b){return( a * sin(x)+ b)}
> trellis.par.set(theme = canonical.theme("Windows"))
> x <- seq(-4,4, by=0.1)
> # case 1x1
> a <- c( 1 )
> b <- c( 3 )
> trel_1 <- xyplot(f(x,a,b) ~ x | a * b, , type = "l", main =
> "1x1", ylab = "f(x)", xlab = "x",
> xlim = c(-6,6), ylim = c(-6,6), )
> # case 3x3
> a <- c(1,2,3)
> b <- c(1,2,3)
> trel_3 <- xyplot(f(x,a,b) ~ x | a * b, , type = "l",
> main = "3x3", ylab = "f(x)", xlab = "x",
> xlim = c(-6,6), ylim = c(-6,6), )
>
> print(trel_3)
> #print(trel_1)
>
> --- end of simple.R ---
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list