Re: [R] panel function with barchart (lattice)

From: Drew <drewbrewit_at_yahoo.com>
Date: Sat 28 Jan 2006 - 02:41:54 EST


Deepayan, thank you for your help!!

After much trial and error (and re-reading the help files), I was able to
come up with what I wanted by making sure the first line of my panel
function looked like this:

                panel = function(y,x,...)

The complete set of code I ended up using:

barchart(yield ~ variety | site, data = barley,

        groups = year,
		layout = c(1,6),
		stack = TRUE,
		auto.key = list(points = FALSE, rectangles = TRUE,
space = "top"),
		scales = list(x = list(abbreviate = TRUE, minlength
= 5, rot = 45)),
		panel = function(y,x,...){
			panel.grid(h = -1, v = 0, col = "gray", lty =

"dotted")
panel.barchart(x,y,...) panel.text(x,y,label = round(y,1),cex=.8) }

)

Thank you for your work on the lattice package! ~Nick

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch]On Behalf Of Deepayan Sarkar
Sent: Wednesday, January 25, 2006 11:30 AM To: Drew
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] panel function with barchart (lattice)

On 1/25/06, Drew <drewbrewit@yahoo.com> wrote:

> Folks at R help,
>
> I can't quite get the panel function to work the way
I
> want within barchart.
> I guess I'm still not understanding how to piece
> together multiple panel
> arguments, especially when "groups" is specified.
>
> Example: I want to be able to add the value of

"yield"
> to each section of
> each bar in this graph:
>
> barchart(yield ~ variety | site, data = barley,
> 	groups = year,
> 	layout = c(1,6),
> 	stack=TRUE,
> 	ylab = "Barley Yield (bushels/acre)"
> )
>
> To do this, I add my panel function:
>
> barchart(yield ~ variety | site, data = barley,
> 	groups = year,
> 	layout = c(1,6),
> 	stack=TRUE,
> 	ylab = "Barley Yield (bushels/acre)",
>
> 	panel = function(x,y,subscripts,groups,...){
> 		panel.barchart(x,y,...)

Well, panel.barchart needs the subscripts and groups arguments to draw
stacked bar charts, and you are calling it without them.

> ltext(x = x, y = y, label =
> round(barley$yield[subscripts],1), cex=.8)

The y values will need to be accumulated. Have you looked at what
panel.barchart does?

> 	}
> )
>
> Then I get the values to print on each bar (which is
> what I want) but the
> bars no longer stack to appropriate height, and I
> cannot get the subsections
> of each bar to be a different color. I've tried
> numerous variations of
> panel.barchart, panel.superpose, etc. using examples
> from ?xyplot, but
> nothing quite works or I get an error message.
>
> Any help would be appreciated.
>
> ~Nick
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>


--
http://www.stat.wisc.edu/~deepayan/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Jan 28 03:07:03 2006

This archive was generated by hypermail 2.1.8 : Sat 28 Jan 2006 - 08:46:24 EST