Re: [R] lattice barchart() with two variables
On Fri, 24 Aug 2018, Richard M. Heiberger wrote: color for the legend comes from trellis.par.get You can control that for an individual plot with the par.settings argument. tmp <- data.frame(y=sample(10), group=rep(c("Median", "Maximum"), each=5), year=factor(rep(1998:1999, length=10))) barchart(y ~ year, data=tmp, group=group, auto.key=TRUE, main="default legend", col = c('grey','black')) barchart(y ~ year, data=tmp, group=group, auto.key=TRUE, main="what you want", par.settings=list(superpose.polygon=list(col=c('grey','black' names(trellis.par.get()) trellis.par.get()$superpose.polygon Thanks, Richard! Before venturing into par.settings I worked off of Bert's advice and careful reading of the ?xyplot details allowed me to fix the two remaining issues. Your suggestions will definitely be of value when I have other complex lattice plots to properly display. Best regards, Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
On Fri, 24 Aug 2018, Bert Gunter wrote: For the legend, you can use the full "key" argument for more control. Bert, This I did. For the scales, again, the docs provide the answer: the "at" and "labels" components of "x" component of the scales lists can explicitly control the x -labels, e.g. A bit of trial-and-error got this working, too. Now the plot command works as desired: barchart(value ~ year, data=stage_heights, panel = lattice.getOption("panel.barchart"), default.prepanel = lattice.getOption("prepanel.default.barchart"), box.ratio = 2, horizontal=FALSE, key=list(c(0.2,0.3), columns=2, text=list(c('Median','Maximum')), rect=list(col=c('black', 'grey'))), groups=factor(type,labels=c('Median','Maximum')), beside=TRUE, col = c('grey','black'), scales=list(x=list(at=rep(1:29), labels=rep(1989:2018),rot=90)), main = 'Median and Maximum Stage Heights', ylab = 'Elevation (masl)', xlab = 'Year') (Emacs w/ESS does the formatting). I suppose that the Maximum bar is plotted to the left because alphabetically it preceeds Medium. I can live with this. Deepayan's book was one of the first I bought years ago. I've not before had plots that required more in-depth knowledge of panels, keys, and scales so I do appreciate your patient mentoring. Best regards, Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
For the legend, you can use the full "key" argument for more control. The docs in ?xyplot for "key" Should answer your questions. "col" controls text color within the "text" component and rectangle color within the "rectangle" component , for example. I think this should work as an alternative to specifying the par.settings components, but I haven't checked. For the scales, again, the docs provide the answer: the "at" and "labels" components of "x" component of the scales lists can explicitly control the x -labels, e.g. scales = list( x = list( at = ..., labels = ...)etc. If you are uncomfortable with the R lattice help docs, and you intend to continue to use lattice plots (a good idea; ggplot is an alternative of course), Deepayan has written a book that you might wish to get: http://lmdvr.r-forge.r-project.org/figures/figures.html There are also numerous web tutorials. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Aug 24, 2018 at 12:38 PM Rich Shepard wrote: > On Wed, 22 Aug 2018, Rich Shepard wrote: > > > More when I have results. > >Almost there. I've read the auto.key section in ?barchart and looked at > examples from stackoverflow on the web without seeing my syntax errors. I > would like help on two issues: > >1. What I want is to have the legend text in black and the colored > rectangles match the black and grey of the bars. Instead, I get the legend > text colored and have no idea where the default colors in the rectangles > got > there. > >2. I've not found how to have the years (rather than the sequence of > years) as the x-axis labels. > >Here are the dput() output and the script: > > structure(list(year = c(1989L, 1989L, 1990L, 1990L, 1991L, 1991L, > 1993L, 1993L, 1994L, 1994L, 1995L, 1995L, 1996L, 1996L, 1997L, > 1997L, 1998L, 1998L, 1999L, 1999L, 2000L, 2000L, 2001L, 2001L, > 2002L, 2002L, 2003L, 2003L, 2004L, 2004L, 2005L, 2005L, 2006L, > 2006L, 2007L, 2007L, 2008L, 2008L, 2009L, 2009L, 2010L, 2010L, > 2011L, 2011L, 2012L, 2012L, 2013L, 2013L, 2014L, 2014L, 2015L, > 2015L, 2016L, 2016L, 2017L, 2017L, 2018L, 2018L), value = c(91.17, > 93.32, 91.22, 93.43, 91.24, 92.89, 91.14, 93.02, 93.92, 95.74, > 94.34, 96.85, 91.32, 95.86, 91.36, 94.25, 91.24, 93.67, 94.33, > 97.42, 94.33, 97.42, 94, 94.99, 94.32, 96.58, 94.02, 96.57, 94.19, > 96.32, 94.05, 95.96, 94.21, 97.4, 94.21, 97.28, 94.32, 96.72, > 94.13, 97.43, 94.27, 95.95, 94.34, 97.82, 94.23, 97, 94.25, 96.6, > 94.15, 96.24, 94.01, 96.68, 94.09, 96.96, 94.31, 96.39, 94.35, > 96.95), type = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, > 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, > 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, > 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, > 1L), .Label = c("Max", "Med"), class = "factor")), class = "data.frame", > row.names = c(NA, > -58L)) > > med_max <- barchart(value ~ year, data=stage_heights, > panel = lattice.getOption("panel.barchart"), > default.prepanel = > lattice.getOption("prepanel.default.barchart"), > box.ratio = 2, horizontal=FALSE, > auto.key=list(space='right', > > col=c('black', 'grey')), > groups=factor(type,labels=c('Median','Maximum')), > beside=TRUE, > col = c('grey','black'), > labels=list(c(1989,1990,1991,1992, 1993,1994, > > 1995,1996,1997,1998,1999,2000,2001, > > 2002,2003,2004,2005,2006,2007,2008, > > 2009,2010,2011,2012,2013,2014,2015, > > 2016,2017,2018), > > scales=list(x=list(rot=90)), > main = 'Median > and Maximum Stage Heights', > ylab = > 'Elevation (masl)', xlab = 'Year') > print(med_max) > > Rich > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
color for the legend comes from trellis.par.get You can control that for an individual plot with the par.settings argument. tmp <- data.frame(y=sample(10), group=rep(c("Median", "Maximum"), each=5), year=factor(rep(1998:1999, length=10))) barchart(y ~ year, data=tmp, group=group, auto.key=TRUE, main="default legend", col = c('grey','black')) barchart(y ~ year, data=tmp, group=group, auto.key=TRUE, main="what you want", par.settings=list(superpose.polygon=list(col=c('grey','black' names(trellis.par.get()) trellis.par.get()$superpose.polygon On Fri, Aug 24, 2018 at 3:37 PM, Rich Shepard wrote: > On Wed, 22 Aug 2018, Rich Shepard wrote: > >> More when I have results. > > > Almost there. I've read the auto.key section in ?barchart and looked at > examples from stackoverflow on the web without seeing my syntax errors. I > would like help on two issues: > > 1. What I want is to have the legend text in black and the colored > rectangles match the black and grey of the bars. Instead, I get the legend > text colored and have no idea where the default colors in the rectangles got > there. > > 2. I've not found how to have the years (rather than the sequence of > years) as the x-axis labels. > > Here are the dput() output and the script: > > structure(list(year = c(1989L, 1989L, 1990L, 1990L, 1991L, 1991L, 1993L, > 1993L, 1994L, 1994L, 1995L, 1995L, 1996L, 1996L, 1997L, 1997L, 1998L, 1998L, > 1999L, 1999L, 2000L, 2000L, 2001L, 2001L, 2002L, 2002L, 2003L, 2003L, 2004L, > 2004L, 2005L, 2005L, 2006L, 2006L, 2007L, 2007L, 2008L, 2008L, 2009L, 2009L, > 2010L, 2010L, 2011L, 2011L, 2012L, 2012L, 2013L, 2013L, 2014L, 2014L, 2015L, > 2015L, 2016L, 2016L, 2017L, 2017L, 2018L, 2018L), value = c(91.17, 93.32, > 91.22, 93.43, 91.24, 92.89, 91.14, 93.02, 93.92, 95.74, 94.34, 96.85, 91.32, > 95.86, 91.36, 94.25, 91.24, 93.67, 94.33, 97.42, 94.33, 97.42, 94, 94.99, > 94.32, 96.58, 94.02, 96.57, 94.19, 96.32, 94.05, 95.96, 94.21, 97.4, 94.21, > 97.28, 94.32, 96.72, 94.13, 97.43, 94.27, 95.95, 94.34, 97.82, 94.23, 97, > 94.25, 96.6, 94.15, 96.24, 94.01, 96.68, 94.09, 96.96, 94.31, 96.39, 94.35, > 96.95), type = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, > 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, > 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, > 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), .Label = c("Max", "Med"), class = > "factor")), class = "data.frame", row.names = c(NA, -58L)) > > med_max <- barchart(value ~ year, data=stage_heights, > panel = lattice.getOption("panel.barchart"), > default.prepanel = > lattice.getOption("prepanel.default.barchart"), > box.ratio = 2, horizontal=FALSE, > auto.key=list(space='right', > > col=c('black', 'grey')), > groups=factor(type,labels=c('Median','Maximum')), > beside=TRUE, > col = c('grey','black'), > labels=list(c(1989,1990,1991,1992, 1993,1994, > > 1995,1996,1997,1998,1999,2000,2001, > > 2002,2003,2004,2005,2006,2007,2008, > > 2009,2010,2011,2012,2013,2014,2015, >2016,2017,2018), > > scales=list(x=list(rot=90)), > main = 'Median and > Maximum Stage Heights', > ylab = 'Elevation > (masl)', xlab = 'Year') > print(med_max) > > > Rich > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
On Wed, 22 Aug 2018, Rich Shepard wrote: More when I have results. Almost there. I've read the auto.key section in ?barchart and looked at examples from stackoverflow on the web without seeing my syntax errors. I would like help on two issues: 1. What I want is to have the legend text in black and the colored rectangles match the black and grey of the bars. Instead, I get the legend text colored and have no idea where the default colors in the rectangles got there. 2. I've not found how to have the years (rather than the sequence of years) as the x-axis labels. Here are the dput() output and the script: structure(list(year = c(1989L, 1989L, 1990L, 1990L, 1991L, 1991L, 1993L, 1993L, 1994L, 1994L, 1995L, 1995L, 1996L, 1996L, 1997L, 1997L, 1998L, 1998L, 1999L, 1999L, 2000L, 2000L, 2001L, 2001L, 2002L, 2002L, 2003L, 2003L, 2004L, 2004L, 2005L, 2005L, 2006L, 2006L, 2007L, 2007L, 2008L, 2008L, 2009L, 2009L, 2010L, 2010L, 2011L, 2011L, 2012L, 2012L, 2013L, 2013L, 2014L, 2014L, 2015L, 2015L, 2016L, 2016L, 2017L, 2017L, 2018L, 2018L), value = c(91.17, 93.32, 91.22, 93.43, 91.24, 92.89, 91.14, 93.02, 93.92, 95.74, 94.34, 96.85, 91.32, 95.86, 91.36, 94.25, 91.24, 93.67, 94.33, 97.42, 94.33, 97.42, 94, 94.99, 94.32, 96.58, 94.02, 96.57, 94.19, 96.32, 94.05, 95.96, 94.21, 97.4, 94.21, 97.28, 94.32, 96.72, 94.13, 97.43, 94.27, 95.95, 94.34, 97.82, 94.23, 97, 94.25, 96.6, 94.15, 96.24, 94.01, 96.68, 94.09, 96.96, 94.31, 96.39, 94.35, 96.95), type = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), .Label = c("Max", "Med"), class = "factor")), class = "data.frame", row.names = c(NA, -58L)) med_max <- barchart(value ~ year, data=stage_heights, panel = lattice.getOption("panel.barchart"), default.prepanel = lattice.getOption("prepanel.default.barchart"), box.ratio = 2, horizontal=FALSE, auto.key=list(space='right', col=c('black', 'grey')), groups=factor(type,labels=c('Median','Maximum')), beside=TRUE, col = c('grey','black'), labels=list(c(1989,1990,1991,1992, 1993,1994, 1995,1996,1997,1998,1999,2000,2001, 2002,2003,2004,2005,2006,2007,2008, 2009,2010,2011,2012,2013,2014,2015, 2016,2017,2018), scales=list(x=list(rot=90)), main = 'Median and Maximum Stage Heights', ylab = 'Elevation (masl)', xlab = 'Year') print(med_max) Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
On Wed, 22 Aug 2018, Bert Gunter wrote: groups = Summary.Type, ... in your call will then do the job. As an aside, this is a good example of why you should adhere to this format for data analysis in R. Bert, Progress and retreat. I'm putting this aside for a day or so because I need to provide my client with a draft report and I can add this plot later when I figure out how to do it correctly. More when I have results. Thanks again, Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
On Wed, 22 Aug 2018, Bert Gunter wrote: (I know that you said your post may already be "out of date", but ...) Bert, Still reading ?xyplot/?barchart. But ?barchart says: "Formally, if groups is specified, then groups along with subscripts is passed to the panel function, ..." which, as I already told you, means you should consult ?panel.barchart . In particular, the example therein tells you exactly how the "groups" argument should be specified and how it works (you can change colors via the "col" argument, of course). Note, in particular, that "groups" must be your grouping variable, which means, in particular, that you need to reformat your data frame in what is currently referred to as "tidy" format (aka "long" format as opposed to "wide") -- one variable per column, one observation per row. That is: Year Value Summary.Type 199191.24 "Med" 199192.89 "Max" ... etc. I saw this in examples and missed its application to my data. You've cleared my confusion and now I _do_ understand the need for a separate grouping column and reshaping to a long format. Thanks for explaining so effectively. As an aside, this is a good example of why you should adhere to this format for data analysis in R. I've done this with all my other data sets and have no excuse for not doing so with this one. Mea culpa! Best regards, Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
(I know that you said your post may already be "out of date", but ...) " Despite additional reading of barchart() examples and help pages I'm still missing how to get grouping working and use the years in the dataframe as labels on the x-axis." But ?barchart says: "Formally, if groups is specified, then groups along with subscripts is passed to the panel function, ..." which, as I already told you, means you should consult ?panel.barchart . In particular, the example therein tells you exactly how the "groups" argument should be specified and how it works (you can change colors via the "col" argument, of course). Note, in particular, that "groups" must be your grouping variable, which means, in particular, that you need to reformat your data frame in what is currently referred to as "tidy" format (aka "long" format as opposed to "wide") -- one variable per column, one observation per row. That is: Year Value Summary.Type 199191.24 "Med" 199192.89 "Max" ... etc. groups = Summary.Type, ... in your call will then do the job. As an aside, this is a good example of why you should adhere to this format for data analysis in R. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Aug 22, 2018 at 10:34 AM Rich Shepard wrote: > On Wed, 22 Aug 2018, Rich Shepard wrote: > > > Correcting the barchard() command fixed the main issue; getting the > second > > set of bars is still eluding me, but I'll continue working on fixing > this. > > I'll get the years as the x-axis labels rather than year number in > > sequence from 1 to 29. > >Despite additional reading of barchart() examples and help pages I'm > still > missing how to get grouping working and use the years in the dataframe as > labels on the x-axis. > >The most recent command version (on the dput output in my previous > message) is: > > med_max <- barchart(stage_heights$Med ~ stage_heights$Year, > horizontal=FALSE, col = 'black', > main = 'Median and Maximum Stage Heights\nUSGS Gauge', > ylab = 'Elevation (masl)', xlab = 'Year', groups=TRUE, > beside=TRUE, panel = "panel.superbar", prepanel = > "prepanel.superbar",) > print(med_max) > >I don't think that conditioning into a trellis applies to this barchart > and I'm not relating the use of scales and labels in a conditioned plot to > the barchart. > >The above command yields an error and I've not found the explanation for > it: > > Error in get(fun, mode = "function", envir = parent.frame()) : >object 'panel.superbar' of mode 'function' was not found > > so I'm definitely not getting the command syntax correct. Help's still > needed. > > Rich > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
On Wed, 22 Aug 2018, Rich Shepard wrote: Correcting the barchard() command fixed the main issue; getting the second set of bars is still eluding me, but I'll continue working on fixing this. I'll get the years as the x-axis labels rather than year number in sequence from 1 to 29. Despite additional reading of barchart() examples and help pages I'm still missing how to get grouping working and use the years in the dataframe as labels on the x-axis. The most recent command version (on the dput output in my previous message) is: med_max <- barchart(stage_heights$Med ~ stage_heights$Year, horizontal=FALSE, col = 'black', main = 'Median and Maximum Stage Heights\nUSGS Gauge', ylab = 'Elevation (masl)', xlab = 'Year', groups=TRUE, beside=TRUE, panel = "panel.superbar", prepanel = "prepanel.superbar",) print(med_max) I don't think that conditioning into a trellis applies to this barchart and I'm not relating the use of scales and labels in a conditioned plot to the barchart. The above command yields an error and I've not found the explanation for it: Error in get(fun, mode = "function", envir = parent.frame()) : object 'panel.superbar' of mode 'function' was not found so I'm definitely not getting the command syntax correct. Help's still needed. Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
On Wed, 22 Aug 2018, Bert Gunter wrote: See inline. Bert, Will do. Sent a reply before seeing this. More to follow. Thanks, Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
See inline. -- Bert On Wed, Aug 22, 2018 at 9:17 AM Rich Shepard wrote: > On Wed, 22 Aug 2018, Bert Gunter wrote: > > > No reproducible example (see posting guide below) so minimal help. > > Hi Bert, > >I thought the header and six data rows of the dataframe plus the syntax > of > the command I used were sufficient. Regardless, here's the dput() output: > > structure(list(Year = c(1989L, 1990L, 1991L, 1993L, 1994L, 1995L, > 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, > 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, > 2014L, 2015L, 2016L, 2017L, 2018L), Med = c(91.17, 91.22, 91.24, > 91.14, 93.92, 94.34, 91.32, 91.36, 91.24, 94.33, 94.33, 94, 94.32, > 94.02, 94.19, 94.05, 94.21, 94.21, 94.32, 94.13, 94.27, 94.34, > 94.23, 94.25, 94.15, 94.01, 94.09, 94.31, 94.35), Max = c(93.32, > 93.43, 92.89, 93.02, 95.74, 96.85, 95.86, 94.25, 93.67, 97.42, > 97.42, 94.99, 96.58, 96.57, 96.32, 95.96, 97.4, 97.28, 96.72, > 97.43, 95.95, 97.82, 97, 96.6, 96.24, 96.68, 96.96, 96.39, 96.95 > )), class = "data.frame", row.names = c(NA, -29L)) > > > > Remove the quotes from your formula. Why did you think they should be > > there? -- see ?formula. > >A prior attempt seemed to suggest the strings needed to be quoted. > > > Read the relevant portions of ?xyplot carefully (again?). You seemed to > > have missed: > >I'm trying to create a barchart, not an xyplot. > Please see ?xyplot, where you will also see dotplot, barchart, etc. documented ! > > > y <- runif(5) > > x <- factor(letters[1:5]) > > barchart(y~x) > >Okay. I see one error in my command that's fixed here: > > barchart(stage_heights$Med ~ stage_heights$Year, horizontal=FALSE) > > > As for fiddling with the colors and patterns of the bars -- generally a > bad > > idea , especially fill patterns, btw -- see the "col" argument of > > ?panel.barchart, which is always where you should look for such info > (i.e. > > panel.whatever). I don't know whether you can fool with fill patterns* -- > > it may depend on your graphics device -- but you can google around or see > > what trellis.par.get() has available (which can be specified in the > > "par.settings" argument list in the call). > >I need pairs of bars, one each for Med and Max for each year. Color or > pattern would distinguish the two. > ?xyplot tells you about the "groups" argument that does exactly this. Again, please read the relevant sections of ?xyplot carefully. > > * For why fooling with fill patterns is a bad idea, google "moiré > patterns". > >I did not think that a solid fill or striped fill would create a moire > pattern on either a computer screen viewing a .pdf file or on the printed > page. > I agree. But color alone usually is the better classifier and suffices; in black and white, light gray vs. black would work as well for just two categories I think. > >Correcting the barchard() command fixed the main issue; getting the > second > set of bars is still eluding me, but I'll continue working on fixing this. > I'll get the years as the x-axis labels rather than year number in sequence > from 1 to 29. > > Thanks, > > Rich > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
On Wed, 22 Aug 2018, Bert Gunter wrote: No reproducible example (see posting guide below) so minimal help. Hi Bert, I thought the header and six data rows of the dataframe plus the syntax of the command I used were sufficient. Regardless, here's the dput() output: structure(list(Year = c(1989L, 1990L, 1991L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L), Med = c(91.17, 91.22, 91.24, 91.14, 93.92, 94.34, 91.32, 91.36, 91.24, 94.33, 94.33, 94, 94.32, 94.02, 94.19, 94.05, 94.21, 94.21, 94.32, 94.13, 94.27, 94.34, 94.23, 94.25, 94.15, 94.01, 94.09, 94.31, 94.35), Max = c(93.32, 93.43, 92.89, 93.02, 95.74, 96.85, 95.86, 94.25, 93.67, 97.42, 97.42, 94.99, 96.58, 96.57, 96.32, 95.96, 97.4, 97.28, 96.72, 97.43, 95.95, 97.82, 97, 96.6, 96.24, 96.68, 96.96, 96.39, 96.95 )), class = "data.frame", row.names = c(NA, -29L)) Remove the quotes from your formula. Why did you think they should be there? -- see ?formula. A prior attempt seemed to suggest the strings needed to be quoted. Read the relevant portions of ?xyplot carefully (again?). You seemed to have missed: I'm trying to create a barchart, not an xyplot. y <- runif(5) x <- factor(letters[1:5]) barchart(y~x) Okay. I see one error in my command that's fixed here: barchart(stage_heights$Med ~ stage_heights$Year, horizontal=FALSE) As for fiddling with the colors and patterns of the bars -- generally a bad idea , especially fill patterns, btw -- see the "col" argument of ?panel.barchart, which is always where you should look for such info (i.e. panel.whatever). I don't know whether you can fool with fill patterns* -- it may depend on your graphics device -- but you can google around or see what trellis.par.get() has available (which can be specified in the "par.settings" argument list in the call). I need pairs of bars, one each for Med and Max for each year. Color or pattern would distinguish the two. * For why fooling with fill patterns is a bad idea, google "moiré patterns". I did not think that a solid fill or striped fill would create a moire pattern on either a computer screen viewing a .pdf file or on the printed page. Correcting the barchard() command fixed the main issue; getting the second set of bars is still eluding me, but I'll continue working on fixing this. I'll get the years as the x-axis labels rather than year number in sequence from 1 to 29. Thanks, Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
No reproducible example (see posting guide below) so minimal help. Remove the quotes from your formula. Why did you think they should be there? -- see ?formula. Read the relevant portions of ?xyplot carefully (again?). You seemed to have missed: "*Primary variables:* The x and y variables should both be numeric in xyplot, and an attempt is made to coerce them if not. However, if either is a factor, the levels of that factor are used as axis labels. In the other four functions documented here, [ which includes barchart()] **exactly one of x and y should be numeric, and the other a factor or shingle**. Which of these will happen is determined by the horizontal argument — if horizontal=TRUE, then y will be coerced to be a factor or shingle, otherwise x. The default value of horizontal is FALSE if x is a factor or shingle, TRUEotherwise. (The functionality provided by horizontal=FALSE is not S-compatible.) So with the default ... horizontal = FALSE, Med would be treated as a factor, which I think is precisely the opposite of what you want. Here is a simple example to indicate how things work: y <- runif(5) x <- factor(letters[1:5]) barchart(y~x) As for fiddling with the colors and patterns of the bars -- generally a bad idea , especially fill patterns, btw -- see the "col" argument of ?panel.barchart, which is always where you should look for such info (i.e. panel.whatever). I don't know whether you can fool with fill patterns* -- it may depend on your graphics device -- but you can google around or see what trellis.par.get() has available (which can be specified in the "par.settings" argument list in the call). * For why fooling with fill patterns is a bad idea, google "moiré patterns". Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Aug 22, 2018 at 8:13 AM Rich Shepard wrote: >I've not before created bar charts, only scatter plots and box plots. > Checking in Deepayan's book, searching the web, and looking at ?barchart > has > not shown me the how to get the results I need. > >The dataframe looks like this: > > head(stage_heights) >Year Med Max > 1 1989 91.17 93.32 > 2 1990 91.22 93.43 > 3 1991 91.24 92.89 > 4 1993 91.14 93.02 > 5 1994 93.92 95.74 > 6 1995 94.34 96.85 > >I want to show Med and Max heights for each Year with each bar having a > different color (or pattern) and a single x-axis year label. > >Trying to follow the example in ?barchart for a single variable > produced this: > > > barchart('Year' ~ 'Med', data=stage_height, > panel=lattice.getOption('panel.barchart'), > default.prepanel=lattice.getOption('prepanel.default.barchart'),box.ratio=2) > Error in eval(substitute(groups), data, environment(formula)) : >invalid 'envir' argument of type 'closure' > and no plot was displayed. > >I must be missing the obvious and want a pointer to descriptions that > teach me how to produce bar charts. > > Rich > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] lattice barchart() with two variables
I've not before created bar charts, only scatter plots and box plots. Checking in Deepayan's book, searching the web, and looking at ?barchart has not shown me the how to get the results I need. The dataframe looks like this: head(stage_heights) Year Med Max 1 1989 91.17 93.32 2 1990 91.22 93.43 3 1991 91.24 92.89 4 1993 91.14 93.02 5 1994 93.92 95.74 6 1995 94.34 96.85 I want to show Med and Max heights for each Year with each bar having a different color (or pattern) and a single x-axis year label. Trying to follow the example in ?barchart for a single variable produced this: barchart('Year' ~ 'Med', data=stage_height, panel=lattice.getOption('panel.barchart'), default.prepanel=lattice.getOption('prepanel.default.barchart'),box.ratio=2) Error in eval(substitute(groups), data, environment(formula)) : invalid 'envir' argument of type 'closure' and no plot was displayed. I must be missing the obvious and want a pointer to descriptions that teach me how to produce bar charts. Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Lattice barchart legend with panel.barchart
Hi Following Pauls reply you may like to increase the panel space available by using useOuterStrips which makes the smaller proportions easier to see and compare If you also wanted to change colours auto.key is the better option. Colours are a bit garish See ?xyplot and panel.barchart library(latticeExtra) useOuterStrips( barchart(Class~Freq|Sex + Age, Titan, groups=Survived, panel = titanpanel, par.settings = list(strip.background = list(col = "transparent"), superpose.polygon= list(col = c("red","blue"), border = c("red","blue"))), stack=TRUE, layout=c(4,1), auto.key=list(title="Survived", text=levels(Titan$Survived), rectangles=TRUE, points=FALSE, columns=2) ) ) Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Seth Bigelow Sent: Thursday, 28 July 2016 07:02 To: r-help@r-project.org Subject: [R] Lattice barchart legend with panel.barchart I have constructed a barchart that requires a panel call, but the panel reduces the facsimiles of bars in the legend to small colored circles. You can see this behavior in the following example: Titan <- as.data.frame(Titanic) titanpanel <- function(x,y,...){ panel.barchart(x,y,...) } barchart(Class~Freq|Sex + Age, Titan, groups=Survived, panel = titanpanel, stack=TRUE, layout=c(4,1), auto.key=list(title="Survived", columns=2)) ...if you comment out the panel and run the barchart statement you will see nice blocks displayed in the legend. Is there any easy way to retain these blocks with panel.barchart? -- Seth W. Bigelow, Ph.D. Assistant Scientist of Forest Ecology Joseph W. Jones Ecological Research Center Newton, GA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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] Lattice barchart legend with panel.barchart
I have constructed a barchart that requires a panel call, but the panel reduces the facsimiles of bars in the legend to small colored circles. You can see this behavior in the following example: Titan <- as.data.frame(Titanic) titanpanel <- function(x,y,...){ panel.barchart(x,y,...) } barchart(Class~Freq|Sex + Age, Titan, groups=Survived, panel = titanpanel, stack=TRUE, layout=c(4,1), auto.key=list(title="Survived", columns=2)) ...if you comment out the panel and run the barchart statement you will see nice blocks displayed in the legend. Is there any easy way to retain these blocks with panel.barchart? -- Seth W. Bigelow, Ph.D. Assistant Scientist of Forest Ecology Joseph W. Jones Ecological Research Center Newton, GA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Lattice Barchart
Pete, Thank you for this example. I recommend using the likert function in the HH package. d2 <- structure(c(1000, 2000, 2500, 5000, 1000, 2000, 3000, 2000, 200, 600, 1000, 900), .Dim = c(4L, 3L), .Dimnames = list(c("1/1/2014", "2/1/2014", "3/1/2014", "4/1/2014"), c("A", "B", "C"))) d2 likert( ~ A+B+C, data=d2, ReferenceZero=1.5, horizontal=FALSE, xTickLabelsPositive=FALSE, xlab="Month", ylab="Difference", panel=function(x, y, ...) { panel.barchart(x, y, ...) panel.xyplot(x=factor(levels(x)), y=tapply(y, x, sum), type="b") }, main="minimal version using likert") ## I put the legend on the right to keep it in the same vertical ## relation as the bars in the plot. likert( ~ A+B+C, data=d2, ReferenceZero=1.5, horizontal=FALSE, xTickLabelsPositive=FALSE, xlab="Month", ylab="Difference", panel=function(x, y, col, col.sum="black", ...) { panel.barchart(x, y, ..., col=col) panel.xyplot(x=factor(levels(x)), y=tapply(y, x, sum), type="b", ..., col=col.sum) }, main="likert with additional arguments", col=c("red","brown","orange"), ## likert colors ## col.sum="black",## optional. col.sum defaults to "black" pch=19, cex=2, lwd=2 ## sum line arguments. ) ## The likert function is defined for positive arguments representing ## counts in various categories. If your 'A' 'B' 'C' correspond to ## 'Disagree' 'Agree' 'Strongly Agree', then this example can be used ## as is. If your 'A' 'B' 'C' have some other type of interpretation, ## then additional work will be needed. Rich On Sun, Feb 16, 2014 at 1:05 PM, Pete Brecknock wrote: > Pete Brecknock wrote >> Hi >> >> The code below plots a stacked barchart. >> >> I would like to overlay on this chart a circular plotting character at the >> sum of the bars for each month. The plotted characters should be joined >> with a line. >> >> So, for "1/1/2014", I would like to see a point at 200 (-1000+1000+200). >> For "2/1/2014" a point at 600 (-2000+2000+600) and so on. >> >> # Barchart Plot >> library(lattice) >> >> d0 <- >> structure(c(-1000,-2000,-2500,-5000,1000,2000,3000,2000,200,600,1000,900), >> .Dim = c(4L, 3L), >> .Dimnames = list(c("1/1/2014", "2/1/2014", "3/1/2014", "4/1/2014"), >> NULL)) >> mycols <- c("red","brown","orange") >> barchart(d0, >> horizontal=FALSE, >> stack=TRUE, >> auto.key=list(text=c("A","B","C"), >>columns =3, >>title="", >>cex.title =0.9, >>border=FALSE), >> xlab="Month", >> ylab="Difference", >> main="Stacked Barchart", >> par.settings = simpleTheme(col = mycols)) >> >> Any pointers would be gratefully received. >> >> Kind regards >> >> Pete > > I put together the following solution but would be interested in any other > approaches people may have to share. > > library(lattice) > library(latticeExtra) > > d0 <- > structure(c(-1000,-2000,-2500,-5000,1000,2000,3000,2000,200,600,1000,900), > .Dim = c(4L, 3L), > .Dimnames = list(c("1/1/2014", "2/1/2014", "3/1/2014", "4/1/2014"), > NULL)) > mycols <- c("red","brown","orange") > > d1 <- data.frame("Dt"=row.names(d0), "Sum"=rowSums(d0)) > > barchart(d0, > horizontal=FALSE, > stack=TRUE, > auto.key=list(text=c("A","B","C"), >columns =3, >title="", >cex.title =0.9, >border=FALSE), > xlab="Month", > ylab="Difference", > main="Stacked Barchart", > par.settings = simpleTheme(col = mycols)) + > > as.layer(xyplot(Sum~Dt, data=d1, type="o", pch=19, cex=1.8, col="black", > lwd=3), y.same=TRUE) > > Thanks > > Pete > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Lattice-Barchart-tp4685387p4685400.html > Sent from the R help mailing list archive at Nabble.com. > > __ > 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] Lattice Barchart
Pete Brecknock wrote > Hi > > The code below plots a stacked barchart. > > I would like to overlay on this chart a circular plotting character at the > sum of the bars for each month. The plotted characters should be joined > with a line. > > So, for "1/1/2014", I would like to see a point at 200 (-1000+1000+200). > For "2/1/2014" a point at 600 (-2000+2000+600) and so on. > > # Barchart Plot > library(lattice) > > d0 <- > structure(c(-1000,-2000,-2500,-5000,1000,2000,3000,2000,200,600,1000,900), > .Dim = c(4L, 3L), > .Dimnames = list(c("1/1/2014", "2/1/2014", "3/1/2014", "4/1/2014"), > NULL)) > mycols <- c("red","brown","orange") > barchart(d0, > horizontal=FALSE, > stack=TRUE, > auto.key=list(text=c("A","B","C"), >columns =3, >title="", >cex.title =0.9, >border=FALSE), > xlab="Month", > ylab="Difference", > main="Stacked Barchart", > par.settings = simpleTheme(col = mycols)) > > Any pointers would be gratefully received. > > Kind regards > > Pete I put together the following solution but would be interested in any other approaches people may have to share. library(lattice) library(latticeExtra) d0 <- structure(c(-1000,-2000,-2500,-5000,1000,2000,3000,2000,200,600,1000,900), .Dim = c(4L, 3L), .Dimnames = list(c("1/1/2014", "2/1/2014", "3/1/2014", "4/1/2014"), NULL)) mycols <- c("red","brown","orange") d1 <- data.frame("Dt"=row.names(d0), "Sum"=rowSums(d0)) barchart(d0, horizontal=FALSE, stack=TRUE, auto.key=list(text=c("A","B","C"), columns =3, title="", cex.title =0.9, border=FALSE), xlab="Month", ylab="Difference", main="Stacked Barchart", par.settings = simpleTheme(col = mycols)) + as.layer(xyplot(Sum~Dt, data=d1, type="o", pch=19, cex=1.8, col="black", lwd=3), y.same=TRUE) Thanks Pete -- View this message in context: http://r.789695.n4.nabble.com/Lattice-Barchart-tp4685387p4685400.html Sent from the R help mailing list archive at Nabble.com. __ 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] Lattice barchart with error bars
> > Anyone know what the 95% confidence > > interval of the median would be? For an R answer you could get one for each group from wilcox.test( , conf.int =TRUE ) and build that into an alternative boxplot stats function which you could specify in your bwplot call. Steve Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] Lattice barchart with error bars
This is not an R question. Read the references. Bert Sent from my iPhone -- please excuse typos. On Jul 5, 2013, at 12:15 PM, Shaun Jackman wrote: > Hmm. Interesting point, Bert. I don't know whether the notches show > the 95% confidence interval or the median, or the 95% confidence > interval that two non-overlapping notches have different medians. > You're saying it's the latter? Anyone know what the 95% confidence > interval of the median would be? > > Cheers, > Shaun > >> The notches (if requested) extend to +/-1.58 IQR/sqrt(n). This seems to be >> based on the same calculations as the formula with 1.57 in Chambers et al. >> (1983, p. 62), given in McGill et al. (1978, p. 16). They are based on >> asymptotic normality of the median and roughly equal sample sizes for the >> two medians being compared, and are said to be rather insensitive to the >> underlying distributions of the samples. The idea appears to be to give >> roughly a 95% confidence interval for the difference in two medians. > > > On 5 July 2013 11:48, Bert Gunter wrote: >> Be careful! >> >> You are talking about 2 different varieties of apples here. As I read >> it, the CI's in the cancer data, which I know is just for example >> purposes, are CI's for the **individual means**; the notches in >> boxplots are nonparametric and for 2 groups with roughly equal sample >> sizes, "The idea appears to be to give roughly a 95% confidence >> interval for the **difference** in two medians." (from >> ?boxplot.stats). So I'm not sure which you want, but they are >> certainly different (by a factor of around sqrt(2),right?), even if >> both are for the mean or both are for the median. >> >> Cheers, >> Bert >> >> On Fri, Jul 5, 2013 at 11:28 AM, David Winsemius >> wrote: >>> >>> On Jul 5, 2013, at 11:15 AM, Shaun Jackman wrote: >>> Hi Bert, Dennis, I'll agree that using a barchart was a poor choice. I was in fact using a notched bwplot to show the median and confidence interval of the median. In this case it's the median and confidence interval that I want to highlight, and I find that the visual noise of the box and whiskers is detracting from the focus, and those wee notches are not much to focus on. So, I'd like to draw a stripplot with error bars, preferably in Lattice. Let's call this a TIE fighter plot. Any suggestions? >>> >>> I like the TIE fighter label. Try this: >>> >>> library(latticeExtra) >>> data(USCancerRates) >>> segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male, >>>data = subset(USCancerRates, state == "Washington"), >>>draw.bands = FALSE, centers = rate.male, >>>segments.fun = panel.arrows, ends = "both", >>>angle = 90, length = 1, unit = "mm") >>> >>> It's what Sarkar has recommended in the past when this request has been >>> posted. >>> >>> -- >>> David >>> >>> Cheers, Shaun On 4 July 2013 18:00, Dennis Murphy wrote: > If you consult the lattice package help, you'll discover there is no > panel_errorbar() function, which would imply the package developers > have a distaste for that type of graphic. If you fish around the > R-help archives, though, you might be able to find someone who wrote a > function to do error bars in lattice. (Use a searchable archive such > as Nabble to hunt for it.) > > Error bar plots are easier to do in the ggplot2 package, since there > is a specific function to generate the error bar 'geometry' > (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded > version of the package help pages, which include the graphs generated > by the code. I believe there's also a base graphics version that you > can get from the gplots package, but I don't know a lot about it. > > Dennis > > On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman wrote: >> Hi, >> >> I'd like to draw a lattice barchart of means with error bars to show >> the standard deviation. I have the barchart, how do I add the error >> bars? >> >> require(datasets) >> require(lattice) >> x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), >> sd=sd(x))) >> barchart(weight[,'mean'] ~ Diet, x) >> >> Thanks, >> Shaun >> >> __ >> 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. [[alternative HTML version deleted]] __ 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,
Re: [R] Lattice barchart with error bars
Hmm. Interesting point, Bert. I don't know whether the notches show the 95% confidence interval or the median, or the 95% confidence interval that two non-overlapping notches have different medians. You're saying it's the latter? Anyone know what the 95% confidence interval of the median would be? Cheers, Shaun > The notches (if requested) extend to +/-1.58 IQR/sqrt(n). This seems to be > based on the same calculations as the formula with 1.57 in Chambers et al. > (1983, p. 62), given in McGill et al. (1978, p. 16). They are based on > asymptotic normality of the median and roughly equal sample sizes for the two > medians being compared, and are said to be rather insensitive to the > underlying distributions of the samples. The idea appears to be to give > roughly a 95% confidence interval for the difference in two medians. On 5 July 2013 11:48, Bert Gunter wrote: > Be careful! > > You are talking about 2 different varieties of apples here. As I read > it, the CI's in the cancer data, which I know is just for example > purposes, are CI's for the **individual means**; the notches in > boxplots are nonparametric and for 2 groups with roughly equal sample > sizes, "The idea appears to be to give roughly a 95% confidence > interval for the **difference** in two medians." (from > ?boxplot.stats). So I'm not sure which you want, but they are > certainly different (by a factor of around sqrt(2),right?), even if > both are for the mean or both are for the median. > > Cheers, > Bert > > On Fri, Jul 5, 2013 at 11:28 AM, David Winsemius > wrote: >> >> On Jul 5, 2013, at 11:15 AM, Shaun Jackman wrote: >> >>> Hi Bert, Dennis, >>> >>> I'll agree that using a barchart was a poor choice. I was in fact using a >>> notched bwplot to show the median and confidence interval of the median. In >>> this case it's the median and confidence interval that I want to highlight, >>> and I find that the visual noise of the box and whiskers is detracting from >>> the focus, and those wee notches are not much to focus on. So, I'd like to >>> draw a stripplot with error bars, preferably in Lattice. Let's call this a >>> TIE fighter plot. Any suggestions? >>> >> >> I like the TIE fighter label. Try this: >> >> library(latticeExtra) >> data(USCancerRates) >> segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male, >> data = subset(USCancerRates, state == "Washington"), >> draw.bands = FALSE, centers = rate.male, >> segments.fun = panel.arrows, ends = "both", >> angle = 90, length = 1, unit = "mm") >> >> It's what Sarkar has recommended in the past when this request has been >> posted. >> >> -- >> David >> >> >>> Cheers, >>> Shaun >>> >>> On 4 July 2013 18:00, Dennis Murphy wrote: >>> If you consult the lattice package help, you'll discover there is no panel_errorbar() function, which would imply the package developers have a distaste for that type of graphic. If you fish around the R-help archives, though, you might be able to find someone who wrote a function to do error bars in lattice. (Use a searchable archive such as Nabble to hunt for it.) Error bar plots are easier to do in the ggplot2 package, since there is a specific function to generate the error bar 'geometry' (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded version of the package help pages, which include the graphs generated by the code. I believe there's also a base graphics version that you can get from the gplots package, but I don't know a lot about it. Dennis On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman wrote: > Hi, > > I'd like to draw a lattice barchart of means with error bars to show > the standard deviation. I have the barchart, how do I add the error > bars? > > require(datasets) > require(lattice) > x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), > sd=sd(x))) > barchart(weight[,'mean'] ~ Diet, x) > > Thanks, > Shaun > > __ > 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. >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> 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. >> >> David Winsemius >> Alameda, CA, USA >> > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-h
Re: [R] Lattice barchart with error bars
Yes! Thank you, David. That's exactly what I'm I'm looking for. For the record, here's a couple pages leading to this answer: http://www.hep.by/gnu/r-patched/r-faq/R-FAQ_89.html http://latticeextra.r-forge.r-project.org/man/segplot.html http://rgm3.lab.nig.ac.jp/RGM/r_function?p=latticeExtra&f=segplot For a related question, what's the tidiest way to calculate the medians and confidence intervals? Currently I'm using `boxplot`: require(datasets) ci <- with(boxplot(weight ~ Diet, ChickWeight), data.frame( Diet = names, median = stats[3,], lower = conf[1,], upper = conf[2,])) Cheers, Shaun On 5 July 2013 11:28, David Winsemius wrote: > > On Jul 5, 2013, at 11:15 AM, Shaun Jackman wrote: > >> Hi Bert, Dennis, >> >> I'll agree that using a barchart was a poor choice. I was in fact using a >> notched bwplot to show the median and confidence interval of the median. In >> this case it's the median and confidence interval that I want to highlight, >> and I find that the visual noise of the box and whiskers is detracting from >> the focus, and those wee notches are not much to focus on. So, I'd like to >> draw a stripplot with error bars, preferably in Lattice. Let's call this a >> TIE fighter plot. Any suggestions? >> > > I like the TIE fighter label. Try this: > > library(latticeExtra) > data(USCancerRates) > segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male, > data = subset(USCancerRates, state == "Washington"), > draw.bands = FALSE, centers = rate.male, > segments.fun = panel.arrows, ends = "both", > angle = 90, length = 1, unit = "mm") > > It's what Sarkar has recommended in the past when this request has been > posted. > > -- > David > > >> Cheers, >> Shaun >> >> On 4 July 2013 18:00, Dennis Murphy wrote: >> >>> If you consult the lattice package help, you'll discover there is no >>> panel_errorbar() function, which would imply the package developers >>> have a distaste for that type of graphic. If you fish around the >>> R-help archives, though, you might be able to find someone who wrote a >>> function to do error bars in lattice. (Use a searchable archive such >>> as Nabble to hunt for it.) >>> >>> Error bar plots are easier to do in the ggplot2 package, since there >>> is a specific function to generate the error bar 'geometry' >>> (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded >>> version of the package help pages, which include the graphs generated >>> by the code. I believe there's also a base graphics version that you >>> can get from the gplots package, but I don't know a lot about it. >>> >>> Dennis >>> >>> On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman wrote: Hi, I'd like to draw a lattice barchart of means with error bars to show the standard deviation. I have the barchart, how do I add the error bars? require(datasets) require(lattice) x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), sd=sd(x))) barchart(weight[,'mean'] ~ Diet, x) Thanks, Shaun __ 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. >>> >> >> [[alternative HTML version deleted]] >> >> __ >> 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. > > David Winsemius > Alameda, CA, USA > __ 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] Lattice barchart with error bars
Be careful! You are talking about 2 different varieties of apples here. As I read it, the CI's in the cancer data, which I know is just for example purposes, are CI's for the **individual means**; the notches in boxplots are nonparametric and for 2 groups with roughly equal sample sizes, "The idea appears to be to give roughly a 95% confidence interval for the **difference** in two medians." (from ?boxplot.stats). So I'm not sure which you want, but they are certainly different (by a factor of around sqrt(2),right?), even if both are for the mean or both are for the median. Cheers, Bert On Fri, Jul 5, 2013 at 11:28 AM, David Winsemius wrote: > > On Jul 5, 2013, at 11:15 AM, Shaun Jackman wrote: > >> Hi Bert, Dennis, >> >> I'll agree that using a barchart was a poor choice. I was in fact using a >> notched bwplot to show the median and confidence interval of the median. In >> this case it's the median and confidence interval that I want to highlight, >> and I find that the visual noise of the box and whiskers is detracting from >> the focus, and those wee notches are not much to focus on. So, I'd like to >> draw a stripplot with error bars, preferably in Lattice. Let's call this a >> TIE fighter plot. Any suggestions? >> > > I like the TIE fighter label. Try this: > > library(latticeExtra) > data(USCancerRates) > segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male, > data = subset(USCancerRates, state == "Washington"), > draw.bands = FALSE, centers = rate.male, > segments.fun = panel.arrows, ends = "both", > angle = 90, length = 1, unit = "mm") > > It's what Sarkar has recommended in the past when this request has been > posted. > > -- > David > > >> Cheers, >> Shaun >> >> On 4 July 2013 18:00, Dennis Murphy wrote: >> >>> If you consult the lattice package help, you'll discover there is no >>> panel_errorbar() function, which would imply the package developers >>> have a distaste for that type of graphic. If you fish around the >>> R-help archives, though, you might be able to find someone who wrote a >>> function to do error bars in lattice. (Use a searchable archive such >>> as Nabble to hunt for it.) >>> >>> Error bar plots are easier to do in the ggplot2 package, since there >>> is a specific function to generate the error bar 'geometry' >>> (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded >>> version of the package help pages, which include the graphs generated >>> by the code. I believe there's also a base graphics version that you >>> can get from the gplots package, but I don't know a lot about it. >>> >>> Dennis >>> >>> On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman wrote: Hi, I'd like to draw a lattice barchart of means with error bars to show the standard deviation. I have the barchart, how do I add the error bars? require(datasets) require(lattice) x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), sd=sd(x))) barchart(weight[,'mean'] ~ Diet, x) Thanks, Shaun __ 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. >>> >> >> [[alternative HTML version deleted]] >> >> __ >> 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. > > David Winsemius > Alameda, CA, USA > -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] Lattice barchart with error bars
On Jul 5, 2013, at 11:15 AM, Shaun Jackman wrote: > Hi Bert, Dennis, > > I'll agree that using a barchart was a poor choice. I was in fact using a > notched bwplot to show the median and confidence interval of the median. In > this case it's the median and confidence interval that I want to highlight, > and I find that the visual noise of the box and whiskers is detracting from > the focus, and those wee notches are not much to focus on. So, I'd like to > draw a stripplot with error bars, preferably in Lattice. Let's call this a > TIE fighter plot. Any suggestions? > I like the TIE fighter label. Try this: library(latticeExtra) data(USCancerRates) segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male, data = subset(USCancerRates, state == "Washington"), draw.bands = FALSE, centers = rate.male, segments.fun = panel.arrows, ends = "both", angle = 90, length = 1, unit = "mm") It's what Sarkar has recommended in the past when this request has been posted. -- David > Cheers, > Shaun > > On 4 July 2013 18:00, Dennis Murphy wrote: > >> If you consult the lattice package help, you'll discover there is no >> panel_errorbar() function, which would imply the package developers >> have a distaste for that type of graphic. If you fish around the >> R-help archives, though, you might be able to find someone who wrote a >> function to do error bars in lattice. (Use a searchable archive such >> as Nabble to hunt for it.) >> >> Error bar plots are easier to do in the ggplot2 package, since there >> is a specific function to generate the error bar 'geometry' >> (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded >> version of the package help pages, which include the graphs generated >> by the code. I believe there's also a base graphics version that you >> can get from the gplots package, but I don't know a lot about it. >> >> Dennis >> >> On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman wrote: >>> Hi, >>> >>> I'd like to draw a lattice barchart of means with error bars to show >>> the standard deviation. I have the barchart, how do I add the error >>> bars? >>> >>> require(datasets) >>> require(lattice) >>> x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), >>> sd=sd(x))) >>> barchart(weight[,'mean'] ~ Diet, x) >>> >>> Thanks, >>> Shaun >>> >>> __ >>> 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. >> > > [[alternative HTML version deleted]] > > __ > 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. David Winsemius Alameda, CA, USA __ 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] Lattice barchart with error bars
Hi Bert, Dennis, I'll agree that using a barchart was a poor choice. I was in fact using a notched bwplot to show the median and confidence interval of the median. In this case it's the median and confidence interval that I want to highlight, and I find that the visual noise of the box and whiskers is detracting from the focus, and those wee notches are not much to focus on. So, I'd like to draw a stripplot with error bars, preferably in Lattice. Let's call this a TIE fighter plot. Any suggestions? Cheers, Shaun On 4 July 2013 18:00, Dennis Murphy wrote: > If you consult the lattice package help, you'll discover there is no > panel_errorbar() function, which would imply the package developers > have a distaste for that type of graphic. If you fish around the > R-help archives, though, you might be able to find someone who wrote a > function to do error bars in lattice. (Use a searchable archive such > as Nabble to hunt for it.) > > Error bar plots are easier to do in the ggplot2 package, since there > is a specific function to generate the error bar 'geometry' > (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded > version of the package help pages, which include the graphs generated > by the code. I believe there's also a base graphics version that you > can get from the gplots package, but I don't know a lot about it. > > Dennis > > On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman wrote: > > Hi, > > > > I'd like to draw a lattice barchart of means with error bars to show > > the standard deviation. I have the barchart, how do I add the error > > bars? > > > > require(datasets) > > require(lattice) > > x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), > > sd=sd(x))) > > barchart(weight[,'mean'] ~ Diet, x) > > > > Thanks, > > Shaun > > > > __ > > 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. > [[alternative HTML version deleted]] __ 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] Lattice barchart with error bars
Shaun: I understand that this type of plot is standard in many disciplines, but it really is awful (google on 'Dynamite plots' for some more erudite perspectives). Have you considered bwplot() for your unaggregated data instead? (No need to reply. It's July 4, and I'm just waving a little flag for better graphs). Cheers, Bert On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman wrote: > Hi, > > I'd like to draw a lattice barchart of means with error bars to show > the standard deviation. I have the barchart, how do I add the error > bars? > > require(datasets) > require(lattice) > x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), > sd=sd(x))) > barchart(weight[,'mean'] ~ Diet, x) > > Thanks, > Shaun > > __ > 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] Lattice barchart with error bars
Hi, I'd like to draw a lattice barchart of means with error bars to show the standard deviation. I have the barchart, how do I add the error bars? require(datasets) require(lattice) x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), sd=sd(x))) barchart(weight[,'mean'] ~ Diet, x) Thanks, Shaun __ 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] Lattice: barchart, error bars and grouped data
Thanks. I switched to ggplot2 which offers error bars. Joh Dieter Menne wrote: > > > Johannes wrote: >> >> >> How can I, given the code snippet below, draw the error bars in the >> center of each grouped bar rather than in the center of the group? >> > > http://markmail.org/message/oljgimkav2qcdyre > > Dieter > __ 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] Lattice: barchart, error bars and grouped data
Johannes wrote: > > > How can I, given the code snippet below, draw the error bars in the center > of each grouped bar rather than in the center of the group? > http://markmail.org/message/oljgimkav2qcdyre Dieter -- View this message in context: http://n4.nabble.com/Lattice-barchart-error-bars-and-grouped-data-tp1584239p1584376.html Sent from the R help mailing list archive at Nabble.com. __ 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] Lattice: barchart, error bars and grouped data
Hi, How can I, given the code snippet below, draw the error bars in the center of each grouped bar rather than in the center of the group? Thanks for any hints, Joh library(lattice) barley[["SD"]] <- 5 barchart( yield ~ variety | site, data = barley, groups=year, origin=0, lowDev=barley[["SD"]], highDev=barley[["SD"]], panel = function( x, y, ..., lowDev, highDev ){ panel.barchart(x, y, ...) panel.segments( as.numeric(x), as.numeric(y) - lowDev, as.numeric(x), as.numeric(y) + highDev, col = 'red', lwd = 2, ...) } ) __ 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] lattice barchart using a time scale in x axis
Thanks a lot for your help, the examples worked fine, just have to change the colours to produce a b&w plot, and add the legend On 05/02/2010 17:11, RICHARD M. HEIBERGER wrote: Fran, The trick is to use box.width, not box.ratio. xyplot(Perc ~ as.POSIXct(hora,format="%d-%m-%Y %H:%M"), data=digrate, groups=Drate, ## key=leg, xlab="time of the day", horizontal=FALSE, scales=list(alternating=FALSE, tck=c(1,0), x=list(at=seq(r[1],r[2],by="hour"), labels=format(seq(r[1],r[2],"hours"), format="%H"))), panel=function(...) { panel.fill(col="white") panel.grid(-1,0,lty=3,col="gray") panel.barchart(...) }, main="xyplot", box.width=5000 ) I also changed the color of the grid to gray. I don't want the background grid visually dominant. Rich __ 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] lattice barchart using a time scale in x axis
Fran, The trick is to use box.width, not box.ratio. xyplot(Perc ~ as.POSIXct(hora,format="%d-%m-%Y %H:%M"), data=digrate, groups=Drate, ## key=leg, xlab="time of the day", horizontal=FALSE, scales=list(alternating=FALSE, tck=c(1,0), x=list(at=seq(r[1],r[2],by="hour"), labels=format(seq(r[1],r[2],"hours"), format="%H"))), panel=function(...) { panel.fill(col="white") panel.grid(-1,0,lty=3,col="gray") panel.barchart(...) }, main="xyplot", box.width=5000 ) I also changed the color of the grid to gray. I don't want the background grid visually dominant. Rich __ 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] lattice barchart using a time scale in x axis
Hi all, Thanks for your answers, it worked, but still can't get the time scale on the x-axis, probably has to do with the unit in the viewport or something like that. But following your recommendation I've prepared some dummy data to go with the scripts. As before we have two graphs, one that has the error I got, and another that has the graph I want to get, but without the time scale as needed. Cheers, Fran Example: #create the dummy data digrate <- data.frame(Perc=runif(30), Drate=rep(letters[1:3], 10), date=c(rep("26-06-2010",9),rep("27-06-2010",21)), hour=rep(c("18:00","20:00","23:00","03:00","05:30","08:00","10:00","14:40","17:30","19:30"),each=3)) digrate$hora<-paste(digrate$date,digrate$hour) digrate library(lattice) # xyplot with panel.barchart, but does not take the groups as in example 2 xyplot(Perc~as.POSIXct(hora,format="%d-%m-%Y %H:%M",origin=strptime(digrate$hora,"%d-%m-%Y %H:%M")), data=digrate, groups=digrate$Drate, ## key=leg, xlab="time of the day", scales=list(alternating=FALSE,tck=c(1,0),x=list(at=seq(r[1],r[2],by="hour"), labels=format(seq(r[1],r[2],"hours"), format="%H:%M"))), panel=function(x,y,groups,...) { panel.fill(col="white") panel.barchart(x, y, groups=groups, horizontal=FALSE, box.ratio=5000, stack=FALSE, ...) }, main="xyplot" ) # barchart example does not get the time scale # get the time range for the x-axes in graph 2 r<-range(strptime(digrate$hora,"%d-%m-%Y %H:%M")) barchart(Perc~as.POSIXct(hora,format="%d-%m-%Y %H:%M"),digrate,groups=Drate,horizontal=F, scales=list(alternating=F,tck=c(1,0),x=list(at=1:10,labels=format(seq(r[1],r[2],"hours"), format="%H:%M"))), panel=function(x,y,...) {panel.fill(col="white") panel.grid(-1,0,lty=3,col="black") panel.barchart(x,y,col=c("white","grey","black"),...)} ) On 05/02/2010 1:56, RICHARD M. HEIBERGER wrote: Fran, Please send to the list some properly structured dummy data. dput(digrate.dummy) would be easiest for me. Rich __ 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] lattice barchart using a time scale in x axis
> SCript with xyplot: > xyplot(Perc~as.POSIXct(hora,format="%d-%m-%Y > %H:%M"),digrate,groups=digrate$Drate,key=leg,xlab="time of the day", > > scales=list(alternating=F,tck=c(1,0),x=list(at=seq(r[1],r[2],by="hour"),labels=format(seq(r[1],r[2],"hours"),format="%H:%M"))), > panel=function(x,y,groups,...) { > panel.fill(col="white") > panel.barchart(x,y,groups,horizontal=F,box.ratio=1000,stack=F,...)} > ) > > Fran You do need to use xyplot() to get control of the x axis. In this example, the problem comes from not specifying the arguments names to panel.barchart. In ?panel.barchart, the third argument is box.ratio. The value of your groups was therefore used as the box.ratio and the widths of the boxes differed by group. Here is a complete working example, with fake data and without r and leg. digrate <- data.frame(Perc=runif(30), Drate=rep(letters[1:3], 10), hora=rep(c(1,2,3,6,8,10,15,20,24,30),each=3)) digrate xyplot(Perc~hora, ## as.POSIXct(hora,format="%d-%m-%Y %H:%M"), data=digrate, groups=digrate$Drate, ## key=leg, xlab="time of the day", scales=list(alternating=FALSE,tck=c(1,0) ##, ## x=list( ## at=seq(r[1],r[2],by="hour"), ## labels=format(seq(r[1],r[2],"hours"), format="%H:%M")) ), panel=function(x,y,groups,...) { panel.fill(col="white") panel.barchart(x, y, groups=groups, horizontal=FALSE, box.ratio=5, stack=FALSE, ...) }, main="xyplot" ) __ 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] lattice barchart using a time scale in x axis
I'm trying to produce a barchart plot with groups, in which each group is placed in a particular time scale in x-axis. If I use barchart directly it does not take the time scale. I've tried with xyplot and adding a panel.barchart, I have the bars in the right place, but not the three groups I'm trying to produce. I've tried defining panel and panel.group, but can't get it to work Drate is a numeric variable with three categories, perc a percentage of preys digested. Script with barchart: barchart(Perc~as.POSIXct(hora,format="%d-%m-%Y %H:%M"),digrate,groups=Drate,horizontal=F, key = leg, scales=list(alternating=F,tck=c(1,0),x=list(at=1:10,labels=format(seq(r[1],r[2],"hours"), format="%H:%M"))), panel=function(x,y,...) {panel.fill(col="white") panel.barchart(x,y,col=c("white","grey","black"),...)} ) SCript with xyplot: xyplot(Perc~as.POSIXct(hora,format="%d-%m-%Y %H:%M"),digrate,groups=digrate$Drate,key=leg,xlab="time of the day", scales=list(alternating=F,tck=c(1,0),x=list(at=seq(r[1],r[2],by="hour"),labels=format(seq(r[1],r[2],"hours"),format="%H:%M"))), panel=function(x,y,groups,...) { panel.fill(col="white") panel.barchart(x,y,groups,horizontal=F,box.ratio=1000,stack=F,...)} ) Fran __ 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] lattice barchart
On Tue, Nov 17, 2009 at 3:31 PM, Wilberforce wrote: > > I have a data frame with two factors and want to create panel barcharts with > one factor defining the panels and the other the vertical categories by > which I can count the rows of data in each combination of factors. How do I > do this? > > I have been trying to use barchart(~factor1|factor2) but it does not give > the panels as I want them. > > The data looks like this: > > Factor1 Factor2 > A y > B y > A x > B y > C x > etc... You need to tabulate your data first; barchart() won't do that for you. Start with barchart(xtabs(~Factor1 + Factor2, your.data)) and try using as.data.frame(xtabs(~Factor1 + Factor2, your.data)) as the data= argument for more flexibility. -Deepayan __ 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] lattice barchart
I have a data frame with two factors and want to create panel barcharts with one factor defining the panels and the other the vertical categories by which I can count the rows of data in each combination of factors. How do I do this? I have been trying to use barchart(~factor1|factor2) but it does not give the panels as I want them. The data looks like this: Factor1Factor2 A y B y A x B y C x etc... -- View this message in context: http://old.nabble.com/lattice-barchart-tp26387179p26387179.html Sent from the R help mailing list archive at Nabble.com. __ 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] Lattice barchart-reordered
Veerappa Chetty wrote: > > Hi,Can I use "reorder" function with barchart as in dotchart? Here are > some > codes which do not work for me. > .. example remove > As your example is not self-contained (it should be), I cannot show it with your data. My preferred way is to reorder outside, because it enforces consistency when I do several plots. Dieter library(lattice) barchart(yield ~ variety | site, data = barley, groups = year, layout = c(1,6), ylab = "Barley Yield (bushels/acre)", scales = list(x = list(abbreviate = TRUE, minlength = 5))) levels(barley$site) = c( "Waseca","Grand Rapids","Duluth","University Farm","Morris" , "Crookston" ) barchart(yield ~ variety | site, data = barley, groups = year, layout = c(1,6), ylab = "Barley Yield (bushels/acre)", scales = list(x = list(abbreviate = TRUE, minlength = 5))) -- View this message in context: http://www.nabble.com/Lattice-barchart-reordered-tp25865201p25867980.html Sent from the R help mailing list archive at Nabble.com. __ 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] Lattice barchart-reordered
Hi,Can I use "reorder" function with barchart as in dotchart? Here are some codes which do not work for me. Thanks Chetty ___ a1c.cast$bmi.cat.reordered[a1c.cast$eth!="Other"] <-with(a1c.cast[a1c.cast$eth!="Other",],reorder(bmi.cat.ordered[a1c.cast$eth!="Other"], BP.FN.RATE,median )) barchart(BP.FN.RATE~ gender|eth,data=a1c.cast[a1c.cast$eth!="Other"&a1c.cast$bmi.cat.reordered!="Other",], groups =bmi.cat.reordered , par.settings = list(superpose.polygon = list(col=c("blue","cyan","red","yellow" )) ), sub=" NHANES-99:06; n = 12,514 " ,ylab= list("Error Rate (%)",cex=1.5), xlab=list("Gender",cex=1.25),auto.key=list(title=" FPG VS A1C for DM Diagnosis: Missed BP",columns=2,cex=1.25), col=c("blue","cyan","red","yellow")) -- Chetty Professor of Family Medicine Boston University Tel: 617-414-6221, Fax:617-414-3345 emails: chett...@gmail.com,vche...@bu.edu [[alternative HTML version deleted]] __ 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] Lattice(barchart) related query
Thanks a bunch, Coltrey! That works like a charm as well! In summary, the code that solves both my queries is shown below: --- mdat <- matrix(c (-2.65,-3.7,-0.8,-1.4,-2.39,-1.12,-4.78,-4.9,-0.76,-1.56, 1.77,1.41,1.92,1.78,0.05,0.96,0.29,1.4,0.53,1.49, 1.4,0.35,1.65,2.14,1.88,2.75,1.86,0.32,2.96,2.28), nrow = 3, ncol=10, byrow=TRUE, dimnames = list(c("A", "B","C"),c ("S-1","S-2","S-3","S-4","S-5","S-6","S-7","S-8","S-9","S-10"))) barchart(mdat, groups=FALSE, layout=c(2,5), aspect=0.7, reference=FALSE, as.table=TRUE, main=list("Maintitle",cex=1), panel=function(x, y, ...) { colours <- character() colours[x < 0] <- 'red' colours[x > 0] <- 'green' panel.barchart(x, y, col=colours, ...) },par.settings=list(grid.pars=list(fontfamily="mono")), xlab="x-axis labels") - -Girish === On Jun 3, 11:20 pm, Coltrey Mather wrote: > No problem. Sorry I ignored your font question, I have no personal > experience, but this may > help:https://stat.ethz.ch/pipermail/r-help/2009-April/196745.html __ 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] Lattice(barchart) related query
No problem. Sorry I ignored your font question, I have no personal experience, but this may help: https://stat.ethz.ch/pipermail/r-help/2009-April/196745.html On Wed, Jun 3, 2009 at 10:17, Girish A.R. wrote: > Thanks, Coltrey! Option 1 is what I was looking for. > > -Girish > > On Jun 3, 8:05 pm, Coltrey Mather wrote: >> barchart(mdat, >> groups=FALSE, >> layout=c(2,5), >> aspect=0.7, >> reference=FALSE, >> as.table=TRUE, >> main=list("Maintitle",cex=1), >> panel=function(x, y, ...) { >> colours <- character() >> colours[x < 0] <- 'red' >> colours[x > 0] <- 'green' >> panel.barchart(x, y, col=colours, ...) >> }, >> xlab="x-axis labels" >> ) >> >> or: >> >> barchart(mdat, >> groups=FALSE, >> col=c(mdat < 0), >> layout=c(2,5), >> aspect=0.7, >> reference=FALSE, >> as.table=TRUE, >> main=list("Maintitle",cex=1), >> xlab="x-axis labels" >> ) >> >> >> >> On Wed, Jun 3, 2009 at 09:42, David Winsemius wrote: >> >> > On Jun 3, 2009, at 9:56 AM, Girish A.R. wrote: >> >> >> Hi, >> >> >> I have been recently experimenting with the lattice package, which I >> >> must admit is just great! However, I'm sort of stuck in modifying >> >> certain parameters; Would appreciate some pointers on a couple of >> >> things: >> >> >> 1) Is it possible to change the font of the labels (say to computer >> >> modern) -- either in the Windows output or thru' Sweave (generating >> >> EPS/PDF)? >> >> 2) As you will notice, there are negative values in the data. Is it >> >> possible to have a different color for the bars depicting negative >> >> values? >> >> >> Reproducible code pasted below: >> >> >> -- >> >> mdat <- matrix(c >> >> (-2.65,-3.7,-0.8,-1.4,-2.39,-1.12,-4.78,-4.9,-0.76,-1.56, >> >> 1.77,1.41,1.92,1.78,0.05,0.96,0.29,1.4,0.53,1.49, >> >> 1.4,0.35,1.65,2.14,1.88,2.75,1.86,0.32,2.96,2.28), nrow = 3, ncol=10, >> >> byrow=TRUE, dimnames = list(c("A", "B","C"),c >> >> ("S-1","S-2","S-3","S-4","S-5","S-6","S-7","S-8","S-9","S-10"))) >> >> >> barchart(mdat, groups=FALSE,layout=c >> >> (2,5),aspect=0.7,reference=FALSE,as.table=TRUE,main=list("Main >> >> title",cex=1),xlab="x-axis labels") >> >> > In you particular instance, I can accomplish the task but I do not know how >> > to do it in a more general fashion, because I do not know how to access the >> > values for the labels internally needed so that an ifelse() test can be >> > constructed. See it this is helpful at any rate: >> >> > barchart(mdat, groups=FALSE,layout=c(2,5), aspect=0.7, reference=FALSE, >> > as.table=TRUE, main=list("Main >> > title",cex=1),xlab="x-axis >> > labels",scales=list(x=list(col=c("red","red","black","black"))) ) >> >> > Deepayan will probably be along shortly with the complete answer. >> >> > Regards; >> > David >> >> > David Winsemius, MD >> > Heritage Laboratories >> > West Hartford, CT >> >> > __ >> > r-h...@r-project.org mailing list >> >https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> >> __ >> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guidehttp://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. > __ 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] Lattice(barchart) related query
Thanks, Coltrey! Option 1 is what I was looking for. -Girish On Jun 3, 8:05 pm, Coltrey Mather wrote: > barchart(mdat, > groups=FALSE, > layout=c(2,5), > aspect=0.7, > reference=FALSE, > as.table=TRUE, > main=list("Maintitle",cex=1), > panel=function(x, y, ...) { > colours <- character() > colours[x < 0] <- 'red' > colours[x > 0] <- 'green' > panel.barchart(x, y, col=colours, ...) > }, > xlab="x-axis labels" > ) > > or: > > barchart(mdat, > groups=FALSE, > col=c(mdat < 0), > layout=c(2,5), > aspect=0.7, > reference=FALSE, > as.table=TRUE, > main=list("Maintitle",cex=1), > xlab="x-axis labels" > ) > > > > On Wed, Jun 3, 2009 at 09:42, David Winsemius wrote: > > > On Jun 3, 2009, at 9:56 AM, Girish A.R. wrote: > > >> Hi, > > >> I have been recently experimenting with the lattice package, which I > >> must admit is just great! However, I'm sort of stuck in modifying > >> certain parameters; Would appreciate some pointers on a couple of > >> things: > > >> 1) Is it possible to change the font of the labels (say to computer > >> modern) -- either in the Windows output or thru' Sweave (generating > >> EPS/PDF)? > >> 2) As you will notice, there are negative values in the data. Is it > >> possible to have a different color for the bars depicting negative > >> values? > > >> Reproducible code pasted below: > > >> -- > >> mdat <- matrix(c > >> (-2.65,-3.7,-0.8,-1.4,-2.39,-1.12,-4.78,-4.9,-0.76,-1.56, > >> 1.77,1.41,1.92,1.78,0.05,0.96,0.29,1.4,0.53,1.49, > >> 1.4,0.35,1.65,2.14,1.88,2.75,1.86,0.32,2.96,2.28), nrow = 3, ncol=10, > >> byrow=TRUE, dimnames = list(c("A", "B","C"),c > >> ("S-1","S-2","S-3","S-4","S-5","S-6","S-7","S-8","S-9","S-10"))) > > >> barchart(mdat, groups=FALSE,layout=c > >> (2,5),aspect=0.7,reference=FALSE,as.table=TRUE,main=list("Main > >> title",cex=1),xlab="x-axis labels") > > > In you particular instance, I can accomplish the task but I do not know how > > to do it in a more general fashion, because I do not know how to access the > > values for the labels internally needed so that an ifelse() test can be > > constructed. See it this is helpful at any rate: > > > barchart(mdat, groups=FALSE,layout=c(2,5), aspect=0.7, reference=FALSE, > > as.table=TRUE, main=list("Main > > title",cex=1),xlab="x-axis > > labels",scales=list(x=list(col=c("red","red","black","black"))) ) > > > Deepayan will probably be along shortly with the complete answer. > > > Regards; > > David > > > David Winsemius, MD > > Heritage Laboratories > > West Hartford, CT > > > __ > > r-h...@r-project.org mailing list > >https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > __ > r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://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] Lattice(barchart) related query
barchart(mdat, groups=FALSE, layout=c(2,5), aspect=0.7, reference=FALSE, as.table=TRUE, main=list("Maintitle",cex=1), panel=function(x, y, ...) { colours <- character() colours[x < 0] <- 'red' colours[x > 0] <- 'green' panel.barchart(x, y, col=colours, ...) }, xlab="x-axis labels" ) or: barchart(mdat, groups=FALSE, col=c(mdat < 0), layout=c(2,5), aspect=0.7, reference=FALSE, as.table=TRUE, main=list("Maintitle",cex=1), xlab="x-axis labels" ) On Wed, Jun 3, 2009 at 09:42, David Winsemius wrote: > > On Jun 3, 2009, at 9:56 AM, Girish A.R. wrote: > >> Hi, >> >> I have been recently experimenting with the lattice package, which I >> must admit is just great! However, I'm sort of stuck in modifying >> certain parameters; Would appreciate some pointers on a couple of >> things: >> >> 1) Is it possible to change the font of the labels (say to computer >> modern) -- either in the Windows output or thru' Sweave (generating >> EPS/PDF)? >> 2) As you will notice, there are negative values in the data. Is it >> possible to have a different color for the bars depicting negative >> values? >> >> Reproducible code pasted below: >> >> -- >> mdat <- matrix(c >> (-2.65,-3.7,-0.8,-1.4,-2.39,-1.12,-4.78,-4.9,-0.76,-1.56, >> 1.77,1.41,1.92,1.78,0.05,0.96,0.29,1.4,0.53,1.49, >> 1.4,0.35,1.65,2.14,1.88,2.75,1.86,0.32,2.96,2.28), nrow = 3, ncol=10, >> byrow=TRUE, dimnames = list(c("A", "B","C"),c >> ("S-1","S-2","S-3","S-4","S-5","S-6","S-7","S-8","S-9","S-10"))) >> >> barchart(mdat, groups=FALSE,layout=c >> (2,5),aspect=0.7,reference=FALSE,as.table=TRUE,main=list("Main >> title",cex=1),xlab="x-axis labels") > > In you particular instance, I can accomplish the task but I do not know how > to do it in a more general fashion, because I do not know how to access the > values for the labels internally needed so that an ifelse() test can be > constructed. See it this is helpful at any rate: > > barchart(mdat, groups=FALSE,layout=c(2,5), aspect=0.7, reference=FALSE, > as.table=TRUE, main=list("Main > title",cex=1),xlab="x-axis > labels",scales=list(x=list(col=c("red","red","black","black"))) ) > > Deepayan will probably be along shortly with the complete answer. > > Regards; > David > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > __ > 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] Lattice(barchart) related query
On Jun 3, 2009, at 9:56 AM, Girish A.R. wrote: Hi, I have been recently experimenting with the lattice package, which I must admit is just great! However, I'm sort of stuck in modifying certain parameters; Would appreciate some pointers on a couple of things: 1) Is it possible to change the font of the labels (say to computer modern) -- either in the Windows output or thru' Sweave (generating EPS/PDF)? 2) As you will notice, there are negative values in the data. Is it possible to have a different color for the bars depicting negative values? Reproducible code pasted below: -- mdat <- matrix(c (-2.65,-3.7,-0.8,-1.4,-2.39,-1.12,-4.78,-4.9,-0.76,-1.56, 1.77,1.41,1.92,1.78,0.05,0.96,0.29,1.4,0.53,1.49, 1.4,0.35,1.65,2.14,1.88,2.75,1.86,0.32,2.96,2.28), nrow = 3, ncol=10, byrow=TRUE, dimnames = list(c("A", "B","C"),c ("S-1","S-2","S-3","S-4","S-5","S-6","S-7","S-8","S-9","S-10"))) barchart(mdat, groups=FALSE,layout=c (2,5),aspect=0.7,reference=FALSE,as.table=TRUE,main=list("Main title",cex=1),xlab="x-axis labels") In you particular instance, I can accomplish the task but I do not know how to do it in a more general fashion, because I do not know how to access the values for the labels internally needed so that an ifelse() test can be constructed. See it this is helpful at any rate: barchart(mdat, groups=FALSE,layout=c(2,5), aspect=0.7, reference=FALSE, as.table=TRUE, main=list("Main title",cex=1),xlab="x-axis labels",scales=list(x=list(col=c("red","red","black","black"))) ) Deepayan will probably be along shortly with the complete answer. Regards; David David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] Lattice(barchart) related query
Hi, I have been recently experimenting with the lattice package, which I must admit is just great! However, I'm sort of stuck in modifying certain parameters; Would appreciate some pointers on a couple of things: 1) Is it possible to change the font of the labels (say to computer modern) -- either in the Windows output or thru' Sweave (generating EPS/PDF)? 2) As you will notice, there are negative values in the data. Is it possible to have a different color for the bars depicting negative values? Reproducible code pasted below: -- mdat <- matrix(c (-2.65,-3.7,-0.8,-1.4,-2.39,-1.12,-4.78,-4.9,-0.76,-1.56, 1.77,1.41,1.92,1.78,0.05,0.96,0.29,1.4,0.53,1.49, 1.4,0.35,1.65,2.14,1.88,2.75,1.86,0.32,2.96,2.28), nrow = 3, ncol=10, byrow=TRUE, dimnames = list(c("A", "B","C"),c ("S-1","S-2","S-3","S-4","S-5","S-6","S-7","S-8","S-9","S-10"))) barchart(mdat, groups=FALSE,layout=c (2,5),aspect=0.7,reference=FALSE,as.table=TRUE,main=list("Main title",cex=1),xlab="x-axis labels") Thanks, -Girish > sessionInfo() R version 2.9.0 (2009-04-17) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States. 1252;LC_MONETARY=English_United States. 1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] RWinEdt_1.8-1 coda_0.13-4verification_1.29 CircStats_0.2-3 [5] boot_1.2-36fields_5.02spam_0.15-4 waveslim_1.6.1 [9] psychometric_2.1 multilevel_2.3 MASS_7.2-47 nlme_3.1-92 [13] languageR_0.953lme4_0.999375-31 Matrix_0.999375-27 zipfR_0.6-5 [17] lattice_0.17-25ggplot2_0.8.3 reshape_0.8.3 plyr_0.1.8 [21] proto_0.3-8doBy_3.9 car_1.2-14 loaded via a namespace (and not attached): [1] cluster_1.12.0 Formula_0.1-3Hmisc_3.6-0 kinship_1.1.0-22 plm_1.1-2 [6] sandwich_2.2-1 splines_2.9.0survival_2.35-4 tools_2.9.0 __ 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.