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
See inline. -- Bert On Wed, Aug 22, 2018 at 9:17 AM Rich Shepard <rshepard at appl-ecosys.com> 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 at 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]]
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
On Wed, 22 Aug 2018, Bert Gunter wrote:> See inline.Bert, Will do. Sent a reply before seeing this. More to follow. Thanks, Rich
(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 1991 91.24 "Med" 1991 92.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 <rshepard at appl-ecosys.com> 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 at 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]]