[R] Make many barplot into one plot

Muhammad Subianto msubianto at gmail.com
Fri Dec 1 18:02:02 CET 2006


Dear all,
## I have 4 tables like this:

satu  <- array(c(5,15,20,68,29,54,84,119), dim=c(2,4),
               dimnames=list(c("Negative", "Positive"), c("Black", 
"Brown", "Red", "Blond")))
dua   <- array(c(50,105,30,8,29,25,84,9), dim=c(2,4),
               dimnames=list(c("Negative", "Positive"), c("Black", 
"Brown", "Red", "Blond")))
tiga  <- array(c(9,16,26,68,12,4,84,12), dim=c(2,4),
               dimnames=list(c("Negative", "Positive"), c("Black", 
"Brown", "Red", "Blond")))
empat <- array(c(25,13,50,78,19,34,84,101), dim=c(2,4),
               dimnames=list(c("Negative", "Positive"), c("Black", 
"Brown", "Red", "Blond")))

## with barplot I can make a plot for each table:

barplot(satu, beside=TRUE, legend.text=rownames(satu),
        ylim = c(0, max(colSums(satu)) * 1.2))
x11()
barplot(dua, beside=TRUE, legend.text=rownames(dua),
        ylim = c(0, max(colSums(dua)) * 1.2))
x11()
barplot(tiga, beside=TRUE, legend.text=rownames(tiga),
        ylim = c(0, max(colSums(tiga)) * 1.2))
x11()
barplot(empat, beside=TRUE, legend.text=rownames(empat),
        ylim = c(0, max(colSums(empat)) * 1.2))

## I can make all barplot above into one plot with

x11(width=11,height=8)
## Make a plot with 2 rows and 2 columns
oldpar <- par(mfrow=c(2,2),
   barplot(above)
par(oldpar)

## Are there any functions to make all barplot above into one plot?
## I would like to produce barplot like:

|   |                               |   |
|   |   |   |   |   |   |   |   |   |   |   |   |   |
|pos|neg|pos|neg|pos|neg|pos|neg|   |pos|neg|pos|neg| ...
|   |   |   |   |   |   |   |   |   |   |   |   |   |
---------------------------------   --------------------
  satu     dua     tiga   empat        satu    dua ...
              black                         blond

I would be grateful if anybody could help me.
Thank you very much.

Muhammad Subianto




More information about the R-help mailing list