Message-ID: <OF0BDC92BD.E2BAD623-ON802575A2.00349071-802575A2.00353379@hsl.gov.uk>
Date: 2009-04-24T09:41:17Z
From: Richard Cotton
Subject: displaying percentage in bar plot
In-Reply-To: <32fc2c8b0904232352v6c54b51asef440e4198b4548d@mail.gmail.com>
> I have a following data
>
> AIS LEvel
> 1 2 3
> body region A 10 15 20
> B 15 25 15
>
> Now I want to plot a barplot and in each bar (corresponding a body
region),
> I need a percentage of AIS level 1 displayed in the plot. Is there an
easy
> way to do this ?
Try this:
x <- matrix(c(10,15,15,25,20,15), ncol=3)
pct <- apply(x, 1, function(x) 100*x[1]/sum(x))
custompanelfn <- function(...)
{
panel.barchart(...)
panel.text(x=c(5,5), y=c(1,2),paste(format(pct, digits=3),"%", sep=""))
}
library(lattice)
barchart(x, panel=custompanelfn)
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}