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]]
Paul Murrell
2016-Jul-27 21:24 UTC
[R] [FORGED] Lattice barchart legend with panel.barchart
Hi
Try this ...
barchart(Class~Freq|Sex + Age, Titan,
groups=Survived,
panel = titanpanel,
stack=TRUE, layout=c(4,1),
key=simpleKey(title="Survived", text=levels(Titan$Survived),
rectangles=TRUE, points=FALSE, columns=2))
Paul
On 28/07/16 09:02, Seth Bigelow wrote:> 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?
>
>
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
Seth Bigelow
2016-Jul-28 01:00 UTC
[R] [FORGED] Lattice barchart legend with panel.barchart
Works great, thank you Paul! On Wed, Jul 27, 2016 at 5:24 PM, Paul Murrell <paul at stat.auckland.ac.nz> wrote:> Hi > > Try this ... > > barchart(Class~Freq|Sex + Age, Titan, > groups=Survived, > panel = titanpanel, > stack=TRUE, layout=c(4,1), > key=simpleKey(title="Survived", text=levels(Titan$Survived), > rectangles=TRUE, points=FALSE, columns=2)) > > Paul > > On 28/07/16 09:02, Seth Bigelow wrote: > >> 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? >> >> >> > -- > Dr Paul Murrell > Department of Statistics > The University of Auckland > Private Bag 92019 > Auckland > New Zealand > 64 9 3737599 x85392 > paul at stat.auckland.ac.nz > http://www.stat.auckland.ac.nz/~paul/ >-- Seth W. Bigelow, Ph.D. Assistant Scientist of Forest Ecology Joseph W. Jones Ecological Research Center Newton, GA (229)-734-4706 x-270 [[alternative HTML version deleted]]
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: mackay at northnet.com.au
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Seth Bigelow
Sent: Thursday, 28 July 2016 07:02
To: r-help at 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 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.