[R] barplot names.arg

David L Carlson dcarlson at tamu.edu
Fri Nov 11 16:04:45 CET 2011


That line in the documentation refers to groups (i.e. columns) on each row
of data. C.1 and C.2 are your groups and if you use the beside=TRUE option
C.1 and C.2 will appear side-by-side with a single labels on the axis
(instead of stacked one atop the other. You could rearrange your data so
that columns C.1 and C.2 in the duplicate weekdays became C3. And C.4 in the
grouped bar graph and the total number of rows in the matrix would be 4.
Using beside=TRUE would give you four bars for Mon/Tue and two bars for
Thur/Fri. But you would not have C.1/C.2 and C.3/C.4 stacked.


----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Diviya Smith
Sent: Thursday, November 10, 2011 11:10 PM
To: R. Michael Weylandt
Cc: r-help at r-project.org
Subject: Re: [R] barplot names.arg

The documentation for bar plots includes -

names.arga vector of names to be plotted below each bar or *group of bars*.
If this argument is omitted, then the names are taken from the names
attribute
of height if this is a vector, or the column names if it is a matrix

Thanks for your suggestion. However, I am still not sure how to group all
the entries for "Mon" and include one label. Your solution sort of does
that but it actually does not print the individual values . I would like to
show that there is a lot of variation in C.1 for "Mon".




On Thu, Nov 10, 2011 at 11:32 PM, R. Michael Weylandt <
michael.weylandt at gmail.com> wrote:

> 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.
> >
>

	[[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