[R] Multiple groups barplot

Jim Lemon jim at bitwrit.com.au
Thu Nov 15 07:13:29 CET 2012


On 11/15/2012 07:21 AM, michele caseposta wrote:
> Back again.
> Is there a quick way to add the sample names in the plot?
> I was not able to find anything other than creating a new category with the name in it (and the same color all over).

Hi Michele,
If by "sample names" you mean the variable names in your data frame:

library(plotrix)
mcdat<-data.frame(smk=c("No","No","Yes"),sex=c("M","M","F"),
  age=c(35,24,30))
sizetree(mcdat,toplab=c("Smoker","Sex","Age"),
  col=list(c("gray80","gray20"),c("pink","lightblue"),rainbow(3)))

This displays the variable names at the top of the stacked bars. If you 
mean the subject codes, then yes, you would have to create a new variable.

Jim




More information about the R-help mailing list