Re: [R] Problem with data frame when using xYplot?
Sorry Deepayan, I forgot that the code moved on while you send your reply. Below the simplified version using your suggestion and this time based on the generic data used in the xYplot manual! Maybe this example can be included in the manual, so next time people will find the answer there. Or better still, you could provide a high level function in 'lattice'. ;-) dfr <- expand.grid(month=1:12, continent=c('Europe','USA'), sex=c('female','male')) set.seed(1) dfr$y <- dfr$month/10 + 1*(dfr$sex=='female') + 2*(dfr$continent=='Europe') + runif(48,-.15,.15) dfr dfs <- summarize(dfr$y, llist(dfr$continent,dfr$sex), smean.cl.normal) labs <- unique(dfs$continent) colnames(dfs) <- list("continent","sex","y","Lower","Upper") dfs$sexnum <- unclass(dfs$sex) dfs xYplot(Cbind(y,Lower,Upper) ~ sexnum|continent, data=dfs, nx=FALSE, xlim=levels(dfs$sex), ylim=c(min(dfs$Lower)-1,max(dfs$Upper)+1), ) dfs$xvar <- rep(1:2, each=2)+rep(c(-0.1,0.1), 2) dfs sp <- list(superpose.symbol = list(pch = c(16,1), cex = 1), superpose.line = list(col = "grey", lty = 1)) xYplot(Cbind(y,Lower,Upper) ~ xvar, groups=sex, data=dfs, xlim= levels(dfs$continent), ylim= c(min(dfs$Lower)-1,max(dfs$Upper)+1), xlab="Continent", panel=function(x, y, type, ...) { panel.xYplot(x, y, type="p",...) lpoints(x, y, pch=16, col="white", cex=2) panel.superpose(x, y, type="p", ...) }, par.settings= sp, auto.key= list(columns=1, x=0.7, y=0.8, corner = c(0,0)) ) Deepayan Sarkar wrote: On Friday 13 May 2005 10:36 am, Sander Oom wrote: Hi Deepayan! Deepayan Sarkar wrote: On Friday 13 May 2005 08:07 am, Sander Oom wrote: An off list response from Mat Soukop (thanks Mat!!) provides an even more elegant solution (see code below)! I have included the original code, so people can decide whether to plot in a single panel or in multiple panels. Now we have a fully functional workaround to get plotmeans{gplots} for multiple factors using lattice! Great! Just out of curiousity, does replacing the 'xlim' and 'scales' arguments above by xlim = levels(tmp$Position) do the same thing? It should with xyplot (which also allows the x variable to be a factor), but xYplot may be bypassing that. You mean: xlim = levels(tmp$AltGeo)yes it does!? No, I meant exactly what I wrote, and my comment followed this piece of code (which you have deleted from your reply): - tmp$PosNum <- unclass(tmp$Position) tmp (labs <- unique(tmp$Position)) # plot factor levels in seperate panels xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE, xlim=c(0.5,2.5), ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), scales = list(x = list(at=seq(1, 2, by=1), labels = labs)), xlab="Position", ylab="Sodium" ) -- No clue how one would ever get comfortable with all these options! By reading the manual, of course :-) Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Dr. Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with data frame when using xYplot?
On Friday 13 May 2005 10:36 am, Sander Oom wrote: > Hi Deepayan! > > Deepayan Sarkar wrote: > > On Friday 13 May 2005 08:07 am, Sander Oom wrote: > >>An off list response from Mat Soukop (thanks Mat!!) provides an even > >>more elegant solution (see code below)! I have included the original > >>code, so people can decide whether to plot in a single panel or in > >>multiple panels. Now we have a fully functional workaround to get > >>plotmeans{gplots} for multiple factors using lattice! Great! > > > > Just out of curiousity, does replacing the 'xlim' and 'scales' arguments > > above by > > > > xlim = levels(tmp$Position) > > > > do the same thing? It should with xyplot (which also allows the x > > variable to be a factor), but xYplot may be bypassing that. > > You mean: xlim = levels(tmp$AltGeo)yes it does!? No, I meant exactly what I wrote, and my comment followed this piece of code (which you have deleted from your reply): - tmp$PosNum <- unclass(tmp$Position) tmp (labs <- unique(tmp$Position)) # plot factor levels in seperate panels xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE, xlim=c(0.5,2.5), ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), scales = list(x = list(at=seq(1, 2, by=1), labels = labs)), xlab="Position", ylab="Sodium" ) -- > No clue how one would ever get comfortable with all these options! By reading the manual, of course :-) Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with data frame when using xYplot?
Hi Deepayan! Deepayan Sarkar wrote: On Friday 13 May 2005 08:07 am, Sander Oom wrote: An off list response from Mat Soukop (thanks Mat!!) provides an even more elegant solution (see code below)! I have included the original code, so people can decide whether to plot in a single panel or in multiple panels. Now we have a fully functional workaround to get plotmeans{gplots} for multiple factors using lattice! Great! Just out of curiousity, does replacing the 'xlim' and 'scales' arguments above by xlim = levels(tmp$Position) do the same thing? It should with xyplot (which also allows the x variable to be a factor), but xYplot may be bypassing that. You mean: xlim = levels(tmp$AltGeo)yes it does!? No clue how one would ever get comfortable with all these options! library(Hmisc) library(lattice) ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme ltheme$strip.background$col <- "transparent" ## change strip bg lattice.options(default.theme = ltheme) ## set as default tmp <- structure(list(Position = structure(as.integer(c(1, 2, 1, 2, 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = c("Basalt-High", "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), Sodium = c(27.3, 26.9, 25, 18.1, 4.67, 5.56, 10.7, 5.67 ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, 15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = c(25.5382783976218, 26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = c(29.1283882690448, 27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = c("Position", "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") tmp$xvar <- rep(1:4, each=2)+rep(c(-0.1,0.1), 4) tmp sp <- list(superpose.symbol = list(pch = c(16,1), cex = 1)) xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position, data=tmp, xlim = levels(tmp$AltGeo), ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), xlab='AltGeo', ylab='Sodium', panel = function(x, y, type, ...) { panel.xYplot(x, y, type="p",...) lpoints(x, y, pch=16, col="white", cex=2) panel.superpose(x, y, type="p", ...) }, par.settings = sp, auto.key=list(columns=1, x=0.7, y=0.8, corner = c(0,0)) ) Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Dr. Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with data frame when using xYplot?
On Friday 13 May 2005 08:07 am, Sander Oom wrote: > An off list response from Mat Soukop (thanks Mat!!) provides an even > more elegant solution (see code below)! I have included the original > code, so people can decide whether to plot in a single panel or in > multiple panels. Now we have a fully functional workaround to get > plotmeans{gplots} for multiple factors using lattice! Great! > > > > > library(Hmisc) > library(lattice) > tmp <- > structure(list(Position = structure(as.integer(c(1, 2, 1, 2, > 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), > AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = > c("Basalt-High", > "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), > Sodium = c(27.3, 26.9, 25, 18.1, > 4.67, 5.56, 10.7, 5.67 > ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, > 15.2679766541317, 5.45435605731786, 8.09492296305393, > 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), > Lower = > c(25.5382783976218, > 26.0818978307592, 18.2793849487813, 13.0217855597339, > 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), > Upper = c(29.1283882690448, > 27.6958799470186, 31.7206150512187, 23.2004366624884, > 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), > .Names = c("Position", > "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", > "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") > tmp$PosNum <- unclass(tmp$Position) > tmp > (labs <- unique(tmp$Position)) > # plot factor levels in seperate panels > xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE, >xlim=c(0.5,2.5), >ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), >scales = list(x = list(at=seq(1, 2, by=1), labels = labs)), >xlab="Position", ylab="Sodium" >) Just out of curiousity, does replacing the 'xlim' and 'scales' arguments above by xlim = levels(tmp$Position) do the same thing? It should with xyplot (which also allows the x variable to be a factor), but xYplot may be bypassing that. Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with data frame when using xYplot?
I have edited the code (hacked from another graph) to provide more control over the different elements of the graph. Now we have a graph at publication quality! Slowly the power of R graphics is shining through the thick cloud of options! Beautiful. library(Hmisc) library(lattice) ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme ltheme$strip.background$col <- "transparent" ## change strip bg lattice.options(default.theme = ltheme) ## set as default tmp <- structure(list(Position = structure(as.integer(c(1, 2, 1, 2, 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = c("Basalt-High", "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), Sodium = c(27.3, 26.9, 25, 18.1, 4.67, 5.56, 10.7, 5.67 ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, 15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = c(25.5382783976218, 26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = c(29.1283882690448, 27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = c("Position", "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") tmp$xvar <- rep(1:4, each=2)+rep(c(-.05,.05), 4) tmp sp <- list(superpose.symbol = list(pch = c(16,1), cex = 1)) xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position, data=tmp, scales=list(y='free',x=list(at=1:4, labels=levels(tmp$AltGeo))), xlim=c(0.5, 4.5), ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), xlab='AltGeo', ylab='Sodium', panel = function(x, y, type, ...) { panel.xYplot(x, y, type="p",...) lpoints(x, y, pch=16, col="white", cex=2) panel.superpose(x, y, type="p", ...) }, par.settings = sp, auto.key=list(columns=1, x=0.7, y=0.8, corner = c(0,0)) ) Sander Oom wrote: An off list response from Mat Soukop (thanks Mat!!) provides an even more elegant solution (see code below)! I have included the original code, so people can decide whether to plot in a single panel or in multiple panels. Now we have a fully functional workaround to get plotmeans{gplots} for multiple factors using lattice! Great! library(Hmisc) library(lattice) tmp <- structure(list(Position = structure(as.integer(c(1, 2, 1, 2, 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = c("Basalt-High", "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), Sodium = c(27.3, 26.9, 25, 18.1, 4.67, 5.56, 10.7, 5.67 ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, 15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = c(25.5382783976218, 26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = c(29.1283882690448, 27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = c("Position", "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") tmp$PosNum <- unclass(tmp$Position) tmp (labs <- unique(tmp$Position)) # plot factor levels in seperate panels xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE, xlim=c(0.5,2.5), ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), scales = list(x = list(at=seq(1, 2, by=1), labels = labs)), xlab="Position", ylab="Sodium" ) new.back <- trellis.par.get("background") new.back$col <- "white" newcol <- trellis.par.get("superpose.symbol") newcol$col <- c('green4','blue','red','black') newcol$pch <- c(16,1,4,8) new.line <- trellis.par.get("box.rectangle") new.line$col <- 'black' trellis.par.set("background", new.back) trellis.par.set("superpose.symbol", newcol) trellis.par.set("box.rectangle", new.line) # Plot factor levels in one graph tmp$xvar <- rep(1:4, each=2)+rep(c(-.05,.05), 4) xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position, data=tmp, scales=list(y='free',x=list(at=1:4, labels=levels(tmp$AltGeo))), xlab='AltGeo', xlim=c(.5, 4.5), key=list(points=Rows(trellis.par.get("superpose.symbol"),1:2), text=list(lab =as.character(levels(tmp$Position)), col=trellis.par.get("superpose.symbol")$col[1:2]), columns=2
Re: [R] Problem with data frame when using xYplot?
An off list response from Mat Soukop (thanks Mat!!) provides an even more elegant solution (see code below)! I have included the original code, so people can decide whether to plot in a single panel or in multiple panels. Now we have a fully functional workaround to get plotmeans{gplots} for multiple factors using lattice! Great! library(Hmisc) library(lattice) tmp <- structure(list(Position = structure(as.integer(c(1, 2, 1, 2, 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = c("Basalt-High", "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), Sodium = c(27.3, 26.9, 25, 18.1, 4.67, 5.56, 10.7, 5.67 ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, 15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = c(25.5382783976218, 26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = c(29.1283882690448, 27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = c("Position", "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") tmp$PosNum <- unclass(tmp$Position) tmp (labs <- unique(tmp$Position)) # plot factor levels in seperate panels xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE, xlim=c(0.5,2.5), ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), scales = list(x = list(at=seq(1, 2, by=1), labels = labs)), xlab="Position", ylab="Sodium" ) new.back <- trellis.par.get("background") new.back$col <- "white" newcol <- trellis.par.get("superpose.symbol") newcol$col <- c('green4','blue','red','black') newcol$pch <- c(16,1,4,8) new.line <- trellis.par.get("box.rectangle") new.line$col <- 'black' trellis.par.set("background", new.back) trellis.par.set("superpose.symbol", newcol) trellis.par.set("box.rectangle", new.line) # Plot factor levels in one graph tmp$xvar <- rep(1:4, each=2)+rep(c(-.05,.05), 4) xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position, data=tmp, scales=list(y='free',x=list(at=1:4, labels=levels(tmp$AltGeo))), xlab='AltGeo', xlim=c(.5, 4.5), key=list(points=Rows(trellis.par.get("superpose.symbol"),1:2), text=list(lab =as.character(levels(tmp$Position)), col=trellis.par.get("superpose.symbol")$col[1:2]), columns=2, cex=1, title="Position", cex.title=1.1)) Sander Oom wrote: Problem solved! I was so focused on reproducing the plotmeans() functionality with xYplot() that I completely overlooked the fact that my data does not allow a x-y plot, as only Sodium is a numeric variable while Position and AltGeo are factors! Using unclass() to make Position a numeric variable does the trick: tmp$Position <- unclass(tmp$Position) The code below does the trick. Now I only need to figure out how to tweak the x axis to pretend I am plotting a factor, i.e. plotting labels "Inside" and "Outside". Cheers, Sander. library(Hmisc) library(Lattice) tmp <- structure(list(Position = structure(as.integer(c(1, 2, 1, 2, 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = c("Basalt-High", "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), Sodium = c(27.3, 26.9, 25, 18.1, 4.67, 5.56, 10.7, 5.67 ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, 15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = c(25.5382783976218, 26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = c(29.1283882690448, 27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = c("Position", "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") tmp$Position <- unclass(tmp$Position) xYplot(Cbind(Sodium,Lower,Upper) ~ Position|AltGeo, groups=AltGeo, data=tmp, ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), xlab="Position", ylab="Sodium" ) Sander Oom wrote: Dear all, I am trying to plot means and error bars using xYplot, but I get an error message from xYplot which I can not figure out: > Error in Summary.factor(..., na.rm = na.rm) : range not meaningful for factors The data frame (tmpNa) was created using aggregate. I have used dump to created t
Re: [R] Problem with data frame when using xYplot?
Problem solved! I was so focused on reproducing the plotmeans() functionality with xYplot() that I completely overlooked the fact that my data does not allow a x-y plot, as only Sodium is a numeric variable while Position and AltGeo are factors! Using unclass() to make Position a numeric variable does the trick: tmp$Position <- unclass(tmp$Position) The code below does the trick. Now I only need to figure out how to tweak the x axis to pretend I am plotting a factor, i.e. plotting labels "Inside" and "Outside". Cheers, Sander. library(Hmisc) library(Lattice) tmp <- structure(list(Position = structure(as.integer(c(1, 2, 1, 2, 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = c("Basalt-High", "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), Sodium = c(27.3, 26.9, 25, 18.1, 4.67, 5.56, 10.7, 5.67 ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, 15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = c(25.5382783976218, 26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = c(29.1283882690448, 27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = c("Position", "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") tmp$Position <- unclass(tmp$Position) xYplot(Cbind(Sodium,Lower,Upper) ~ Position|AltGeo, groups=AltGeo, data=tmp, ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1), xlab="Position", ylab="Sodium" ) Sander Oom wrote: Dear all, I am trying to plot means and error bars using xYplot, but I get an error message from xYplot which I can not figure out: > Error in Summary.factor(..., na.rm = na.rm) : range not meaningful for factors The data frame (tmpNa) was created using aggregate. I have used dump to created the code below, which generates the same error. Can anybody tell me what is wrong with the data frame? Thanks in advance, Sander. library(Hmisc) tmpNa <- structure(list(Position = structure(as.integer(c(1, 2, 1, 2, 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"), AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = c("Basalt-High", "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"), Sodium = c(27.3, 26.9, 25, 18.1, 4.67, 5.56, 10.7, 5.67 ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560, 15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = c(25.5382783976218, 26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = c(29.1283882690448, 27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = c("Position", "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") xYplot(Cbind(Sodium,Lower,Upper) ~ AltGeo, groups=Position, data=tmpNa) > version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R -- Dr. Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html