Re: [R] Subsetting within xyplot()
See the description of the subset argument in ?xyplot subset: logical or integer indexing vector (can be specified in terms of variables in 'data'). Only these rows of 'data' will be used for the plot. If 'subscripts' is 'TRUE', the subscripts will provide indices to the rows of data before the subsetting is done. Whether levels of factors in the data frame that are unused after the subsetting will be dropped depends on the 'drop.unused.levels' argument. That is not what you are passing. David Afshartous wrote: > All, > > I'm having problems w/ a simple attempt to subset an xyplot. > > The first plot below is a plot of y versus x for certain values of a third > categorical variable z. Now I'd like to further restrict this to certain > values of variable y. Neither of the two attempts below work. Any > suggestions much appreciated. (note: I don't want to merely use ylim since > I have a loess plot and I want this to be calculated w/ the restricted > values). > > Thanks, > David > > > > > y = c( 0.4, 0.6, -0.1, 0.3, 0.3, -0.2, 0.7, 0.7, 0.2, 0.0, 0.9, > -0.1, 0.6, -1.1, 0.8, -1.0, 0.4, 0.1, 0.7, -0.2, -0.1, -0.1, 2.2, > 0.7, 1.1, 0.2, -0.2, -0.9, 0.4, 0.1, -0.3, -0.4) > x = c(4.1000, 4.9600, 1.2000, 3.9000, 3.1875, 1.9000, 1.8625, > 0.7650, 1.5750, 2.4700, 1.6250, 1.5500, 2.3125, 1.3125, 1.0600, > -0.5500, 1.1000, 0.0200, -0.0375, 3.4600, 2.5250, 2.0950, 0.8000, > 1.6050, -0.4150, -0.7300, 1.1550, 1.4850, 2.2000, 2.2500, 0.6000, > 2.1000) > junk.frm = data.frame(x, y, z = rep(c("D", "P"), 16)) > > xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", > "smooth"), pch = 20) > > xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", > "smooth"), pch = 20, > , subset = junk.frm[junk.frm$y < 2, ]) > Error in tmp[subset] : invalid subscript type 'list' > > xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", > "smooth"), pch = 20, > data = junk.frm[junk.frm$y < 2 & junk.frm$z =="D", ]) > Error in xyplot(y ~ x, data = junk.frm[junk.frm$z == "D", ], type = c("g", > : > formal argument "data" matched by multiple actual arguments > > __ > R-help@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. __ R-help@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.
Re: [R] Subsetting within xyplot()
Try this: xyplot(y ~ x , data = junk.frm, type = c("g", "p","smooth"), pch=20, subset=z=="D" & y < 2) On 26/02/2008, David Afshartous <[EMAIL PROTECTED]> wrote: > > All, > > I'm having problems w/ a simple attempt to subset an xyplot. > > The first plot below is a plot of y versus x for certain values of a third > categorical variable z. Now I'd like to further restrict this to certain > values of variable y. Neither of the two attempts below work. Any > suggestions much appreciated. (note: I don't want to merely use ylim since > I have a loess plot and I want this to be calculated w/ the restricted > values). > > Thanks, > David > > > > > y = c( 0.4, 0.6, -0.1, 0.3, 0.3, -0.2, 0.7, 0.7, 0.2, 0.0, 0.9, > -0.1, 0.6, -1.1, 0.8, -1.0, 0.4, 0.1, 0.7, -0.2, -0.1, -0.1, 2.2, > 0.7, 1.1, 0.2, -0.2, -0.9, 0.4, 0.1, -0.3, -0.4) > x = c(4.1000, 4.9600, 1.2000, 3.9000, 3.1875, 1.9000, 1.8625, > 0.7650, 1.5750, 2.4700, 1.6250, 1.5500, 2.3125, 1.3125, 1.0600, > -0.5500, 1.1000, 0.0200, -0.0375, 3.4600, 2.5250, 2.0950, 0.8000, > 1.6050, -0.4150, -0.7300, 1.1550, 1.4850, 2.2000, 2.2500, 0.6000, > 2.1000) > junk.frm = data.frame(x, y, z = rep(c("D", "P"), 16)) > > xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", > "smooth"), pch = 20) > > xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", > "smooth"), pch = 20, > , subset = junk.frm[junk.frm$y < 2, ]) > Error in tmp[subset] : invalid subscript type 'list' > > xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", > "smooth"), pch = 20, > data = junk.frm[junk.frm$y < 2 & junk.frm$z =="D", ]) > Error in xyplot(y ~ x, data = junk.frm[junk.frm$z == "D", ], type = c("g", > : > formal argument "data" matched by multiple actual arguments > > __ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O __ R-help@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.
[R] Subsetting within xyplot()
All, I'm having problems w/ a simple attempt to subset an xyplot. The first plot below is a plot of y versus x for certain values of a third categorical variable z. Now I'd like to further restrict this to certain values of variable y. Neither of the two attempts below work. Any suggestions much appreciated. (note: I don't want to merely use ylim since I have a loess plot and I want this to be calculated w/ the restricted values). Thanks, David y = c( 0.4, 0.6, -0.1, 0.3, 0.3, -0.2, 0.7, 0.7, 0.2, 0.0, 0.9, -0.1, 0.6, -1.1, 0.8, -1.0, 0.4, 0.1, 0.7, -0.2, -0.1, -0.1, 2.2, 0.7, 1.1, 0.2, -0.2, -0.9, 0.4, 0.1, -0.3, -0.4) x = c(4.1000, 4.9600, 1.2000, 3.9000, 3.1875, 1.9000, 1.8625, 0.7650, 1.5750, 2.4700, 1.6250, 1.5500, 2.3125, 1.3125, 1.0600, -0.5500, 1.1000, 0.0200, -0.0375, 3.4600, 2.5250, 2.0950, 0.8000, 1.6050, -0.4150, -0.7300, 1.1550, 1.4850, 2.2000, 2.2500, 0.6000, 2.1000) junk.frm = data.frame(x, y, z = rep(c("D", "P"), 16)) xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", "smooth"), pch = 20) xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", "smooth"), pch = 20, , subset = junk.frm[junk.frm$y < 2, ]) Error in tmp[subset] : invalid subscript type 'list' xyplot(y ~ x , data = junk.frm[junk.frm$z =="D",], type = c("g", "p", "smooth"), pch = 20, data = junk.frm[junk.frm$y < 2 & junk.frm$z =="D", ]) Error in xyplot(y ~ x, data = junk.frm[junk.frm$z == "D", ], type = c("g", : formal argument "data" matched by multiple actual arguments __ R-help@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.