[R] component chart

Paul Murrell paul at stat.auckland.ac.nz
Wed Jul 11 02:33:29 CEST 2001


> How do I create a component chart using R? For example, given the
following data:
>               1994
> sales         80,000
> maintenace    20,000
> I want to create a horizontal bar graph where sales starts from 0 to
80,000 and maintenance starts from 80,000 to 100,000. I also want to display
the total as another bar starting from 0 to 100,000.

Sounds like you need the barplot() function.. For example (not very polished
:) ...

    barplot(matrix(c(8,2,0,10),ncol=2), horiz=T)

... or (_slightly_ more polished) ...

    barplot(matrix(c(8,2,0,0,0,10),ncol=2), col=c("red","green","blue"),
                horiz=T, names=c("Components", "Total"),
                legend.text=c("Sales", "Maintenance", "Total"),
                space=0.5, xlim=c(0, 15))

Hope that helps


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list