[R] barplot names.arg

R. Michael Weylandt michael.weylandt at gmail.com
Fri Nov 11 05:32:40 CET 2011


I'm not sure you can do that data aggregation in barplot directly (a
quick skim doesn't reveal anything in the documentation that suggests
it to me, thought I might have missed it) though I think this does
what you are talking about:

barplot(sapply(unique(rownames(mdat)), function(n)
colSums(mdat[n,,drop=F])), col = rainbow(2))

Michael

On Thu, Nov 10, 2011 at 9:21 PM, Diviya Smith <diviya.smith at gmail.com> wrote:
> Hello there,
>
> I have a question regarding bar plots. I am trying to plot the data from
> the following matrix as a barplot -
>
> # input data
> mdat <- matrix(c(0.1,0.9,0.9,0.1,0.5,0.5,0.45,1-0.45,0.6,0.4,0.8,0.2), nrow
> = 6, ncol=2, byrow=TRUE,
> +                dimnames = list(c("Mon", "Mon", "Tues", "Tues", "Thurs",
> "Friday"),
> +                                c("C.1", "C.2")))
>
> # plot
>
> barplot(t(as.matrix(mdat)), col=rainbow(2), ylab="Sales", names.arg =
> rownames(mdat), border=NA, cex.names=0.5)
>
>
> I am using names.arg to print the label for the bars. However, I would like
> to group all the entries for the Mon and print the label only once. Is
> there a way to do this? The documentation for barplots suggests that this
> can be done but I was not able to figure it out. Please help.
>
>
> Thanks in advance,
>
> Diviya
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list