[R] multiple bar for barchart

Jim Lemon jim at bitwrit.com.au
Tue Dec 10 00:25:17 CET 2013


On 12/10/2013 01:19 AM, Adel ESSAFI wrote:
> Hello list,
> I have the following data on "dm" table
>
>> dm
>     Group.1 V1   V2      V3        V4         V5      V6      V7         V8
> 1      C/L NA 15.5  732179  875270.6 -143091.46 1107270 1088300   18964.40
> 2      C/S NA 15.5  803926  850352.1  -46426.03 1395710 1312310   83403.30
> 3      D/D NA 15.5  751660  857828.2 -106168.17 1340360 1322790   17569.30
> 4      D/F NA 15.5  724924  969418.7 -244494.67 1181280 1160760   20519.20
> 5      D/I NA 15.5  755841  842130.5  -86289.48 1264250 1241750   22495.20
> 6      D/L NA 15.5  731904  875340.0 -143435.84 1107600 1087940   19657.30
> 7      D/S NA 15.5  798289  844102.0  -45812.85 1399840 1305000   94832.10
> 8      I/F NA 15.5  871670 1074136.3 -202466.58 1304290 1249006   55286.59
> 9      I/I NA 15.5  897718 1029579.0 -131861.35 1542810 1398716  144100.07
> 10     I/L NA 15.5 2628110  862466.8 1765645.67 2628110 1073510 1554610.00
> 11     I/S NA 15.5 2628110  831486.8 1796627.33 2475450 1282100 1193350.00
>> barchart (dm[,4] ~ dm[,1])
>
> For each value of Group.1 I want to draw 4 bars (v3,v4, v6 and v7).
>
> Can you suggest me a solution please
>
Hi Adel,
If you have no repeated values in Group.1, this might work:

dmmat<-as.matrix(dm[,c(3,4,6,7)])
rownames(dmmat)<-as.character(dm$Group.1)
library(plotrix)
barp(t(dmmat),names.arg=rownames(dmmat))

Jim



More information about the R-help mailing list