[R] Matrix barplot
Andreas Tille
tillea at rki.de
Fri Jul 25 21:29:10 CEST 2008
On Fri, 25 Jul 2008, Nutter, Benjamin wrote:
>> data <- data.frame(Year=c(2000,2001,2002),
> A=c(4,2,1),
> B=c(3,1,2),
> C=c(0,3,5))
>
>> data.mat <- as.matrix(data)[,2:4]
>> rownames(data.mat) <- data$Year
>> data.mat <- t(data.mat)
>> barplot(data.mat,beside=TRUE)
As I said this works great - but now I would like to use the table
heading as legend - and have no idea how to access the header (see below)
>
> -----Original Message-----
> On Behalf Of Andreas Tille
> Sent: Friday, July 25, 2008 8:14 AM
> To: r-help at r-project.org
> Subject: [R] Matrix barplot
>
> Year A B C
> 2000 4 3 0
> 2001 2 1 3
> 2002 1 2 5
What do I need to specify as legend.text in the barplot command
to get A / B / C in the legend if I read the file using
data <- read.table(file='data.dat', sep = '\t', fill=TRUE, header=TRUE )
Kind regards
Andreas.
--
http://fam-tille.de
More information about the R-help
mailing list