[R] Matrix barplot

Jim Lemon jim at bitwrit.com.au
Fri Jul 25 14:47:46 CEST 2008


On Fri, 2008-07-25 at 14:13 +0200, Andreas Tille wrote:
> Hi,
> 
> as a bloody R beginner I failed to solve the probably simple problem
> to create a barplot of the following data read from a file
> 
>       Year      A     B    C
>       2000      4     3    0
>       2001      2     1    3
>       2002      1     2    5
> 
> The Barplot should look like
> 
>      5 |                 C
>      4 |   A             C
>      3 |   AB      C     C
>      2 |   AB    A C    BC
>      1 |   AB    ABC   ABC
>        +------------------
>           2000  2001  2002
> 
> (well, something like that - the colors are encoded as letters in this
>   ASCII-graphics - assume the coloring / shading as usual).
> 
Hi Andreas,
Try this (assume your data frame is named "atdat"):

library(plotrix)
# barp groups data in columns, not rows, so transpose
barp(t(atdat[,2:4]),names.arg=atdat[,1],col=2:4)

Jim



More information about the R-help mailing list