I've a data frame with this structure: 'data.frame': 1987 obs. of 11 variables: $ site : Factor w/ 24 levels "B(W)","BC-1",..: 1 1 2 2 2 1 1 1 ... $ sampdate : Date, format: "2000-07-18" "2000-07-18" ... $ tclass : Factor w/ 8 levels "Annelida","Arachnida",..: 1 5 5 5 5 ... $ torder : Factor w/ 18 levels "Achtinedida",..: 13 5 5 10 13 5 7 ... $ tfamily : Factor w/ 81 levels "","Ameletidae",..: 79 46 46 14 42 ... $ tgenus : Factor w/ 206 levels "","Acentrella",..: 1 10 10 1 140 ... $ tspecies : Factor w/ 60 levels "","aequalis",..: 1 1 1 1 1 1 1 ... $ quant : int 22 527 22 22 11 97 333 11 108 11 ... $ stream : Factor w/ 7 levels "BCrk","JCrk",..: 1 1 1 1 1 1 1 1 ... $ basin : Factor w/ 2 levels "H","O": 2 2 2 2 2 2 2 2 2 2 ... When I create a bar chart for tclass by stream the resulting bars appear to have multiple segments (see attached pdf) from this command: barchart(quant ~ tclass | stream, data = benthos, main = 'Taxonomic Classes', xlab = 'Class Name', ylab = 'Number/square meter', scales = list(x = list(rot = 90))) and I want to understand what the segments represent. I thought the formula 'quant ~ tclass' would produce one bar per class. I cannot find the answer in the ?barchart help page (it may be there and I'm not seeing it) or the Lattice book. Your help in increasing my understanding is appreciated. TIA, Rich -------------- next part -------------- A non-text attachment was scrubbed... Name: class-by-stream.pdf Type: application/pdf Size: 9829 bytes Desc: URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121023/b149c211/attachment.pdf>
Understanding lattice barchart() display
5 messages · Bert Gunter, Rich Shepard, Peter Ehlers
I believe you are misunderstanding what a barchart is (or maybe I do, since I never use 'em). I believe that there should be one quant value for each tclass and stream, and you have several. ?panel.barchart is the place to look for documentation for details of any lattice display. Note especially the "horizontal" argument details (also in ?barchart). You may also wish to consider ?bwplot instead. -- Bert
On Tue, Oct 23, 2012 at 2:59 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
I've a data frame with this structure: 'data.frame': 1987 obs. of 11 variables: $ site : Factor w/ 24 levels "B(W)","BC-1",..: 1 1 2 2 2 1 1 1 ... $ sampdate : Date, format: "2000-07-18" "2000-07-18" ... $ tclass : Factor w/ 8 levels "Annelida","Arachnida",..: 1 5 5 5 5 ... $ torder : Factor w/ 18 levels "Achtinedida",..: 13 5 5 10 13 5 7 ... $ tfamily : Factor w/ 81 levels "","Ameletidae",..: 79 46 46 14 42 ... $ tgenus : Factor w/ 206 levels "","Acentrella",..: 1 10 10 1 140 ... $ tspecies : Factor w/ 60 levels "","aequalis",..: 1 1 1 1 1 1 1 ... $ quant : int 22 527 22 22 11 97 333 11 108 11 ... $ stream : Factor w/ 7 levels "BCrk","JCrk",..: 1 1 1 1 1 1 1 1 ... $ basin : Factor w/ 2 levels "H","O": 2 2 2 2 2 2 2 2 2 2 ... When I create a bar chart for tclass by stream the resulting bars appear to have multiple segments (see attached pdf) from this command: barchart(quant ~ tclass | stream, data = benthos, main = 'Taxonomic Classes', xlab = 'Class Name', ylab = 'Number/square meter', scales = list(x = list(rot = 90))) and I want to understand what the segments represent. I thought the formula 'quant ~ tclass' would produce one bar per class. I cannot find the answer in the ?barchart help page (it may be there and I'm not seeing it) or the Lattice book. Your help in increasing my understanding is appreciated. TIA, Rich
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
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
On Tue, 23 Oct 2012, Bert Gunter wrote:
I believe you are misunderstanding what a barchart is (or maybe I do, since I never use 'em). I believe that there should be one quant value for each tclass and stream, and you have several.
Bert, My first attempt at using barchart()
?panel.barchart is the place to look for documentation for details of any lattice display. Note especially the "horizontal" argument details (also in ?barchart).
I looked at the panel section in ?barchart but did not gain any insights into why there are segments in the bars.
You may also wish to consider ?bwplot instead.
Sure. I thought of that, too. Those I've used before. Thanks, Rich
On 2012-10-23 15:39, Rich Shepard wrote:
On Tue, 23 Oct 2012, Bert Gunter wrote:
I believe you are misunderstanding what a barchart is (or maybe I do, since I never use 'em). I believe that there should be one quant value for each tclass and stream, and you have several.
Bert,
My first attempt at using barchart()
?panel.barchart is the place to look for documentation for details of any lattice display. Note especially the "horizontal" argument details (also in ?barchart).
I looked at the panel section in ?barchart but did not gain any insights
into why there are segments in the bars.
As Bert correctly points out, you have more than one quant value per
tclass/stream combination. You need to summarize your 1987-case
data.frame to a 56-case data.frame (8 levels of tclass and 7 levels
of stream). The easy way to do that is:
benthos2 <- aggregate(quant ~ tclass + stream, data = benthos,
FUN = sum)
Then just use benthos2 as the data argument to barchart().
Peter Ehlers
On Tue, 23 Oct 2012, Peter Ehlers wrote:
As Bert correctly points out, you have more than one quant value per
tclass/stream combination. You need to summarize your 1987-case data.frame
to a 56-case data.frame (8 levels of tclass and 7 levels of stream). The
easy way to do that is:
benthos2 <- aggregate(quant ~ tclass + stream, data = benthos,
FUN = sum)
Then just use benthos2 as the data argument to barchart().
Peter, Thank you. I'll learn the aggregate function and do as you suggest. Regards, Rich