[R] sample size in box plot labels
PIKAL Petr
petr.pikal at precheza.cz
Fri Apr 26 14:38:13 CEST 2013
Hi
actually it shall be the same result as
table(DATA$UnitName_1)
Both approaches does not work if there are NAs in your data.
tapply(DATA$K_Merge, DATA$UnitName_1, FUN = function(x) sum(!is.na(x)))
consideres also NA values.
Regards
Petr
---Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Shane Carey
> Sent: Friday, April 26, 2013 1:09 PM
> To: Rui Barradas
> Cc: r-help at r-project.org
> Subject: Re: [R] sample size in box plot labels
>
> This works, great. Cheers
>
>
> On Fri, Apr 26, 2013 at 12:02 PM, Rui Barradas <ruipbarradas at sapo.pt>
> wrote:
>
> > Hello,
> >
> > To count the sample sizes for each factor try
> >
> > tapply(DATA$K_Merge, DATA$UnitName_1, FUN = length)
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Em 26-04-2013 10:48, Shane Carey escreveu:
> >
> > Hi,
> >>
> >> I would like to put the sample number beside each lable in a
> boxplot.
> >> How do I do this? Essentially, I need to count the sample size for
> >> each factor, see below:
> >> Thanks
> >>
> >>
> boxplot(DATA$K_Merge~factor(**DATA$UnitName_1),axes=FALSE,**col=colou
> >> rs) title(main=list("Tukey Boxplot by Geology:\n K(%)",cex=cexlb))
> >> axis(1, 1:21, labels=FALSE, las=2) text(seq(1, 21, by=1),
> >> par("usr")[3], labels = levels(factor(DATA$UnitName_1)**), srt = 45,
> >> adj = c(1.03,1.03), xpd = TRUE,
> >> cex=1.8)
> >> axis(2, seq(-1,5, 1), seq(-1, 5, 1))
> >>
> >>
> >>
>
>
> --
> Shane
>
> [[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