[R] Labelling boxplot with fivenumber summary

jim holtman jholtman at gmail.com
Fri Apr 6 19:02:14 CEST 2007

Here is one way of labeling the values:

# capture data returned by boxplot
x <- boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
# plot each group
for (i in seq(ncol(x$stats))){
    text(i, x$stats[,i], labels=x$stats[,i])
# if there are outliers, plot them
if (length(x$out) > 0){
    # split the groups so you can get max/min
    maxmin <- split(x$out, x$group)
    # go through each group getting min/max
    lapply(names(maxmin), function(.grp){
        .range <- range(maxmin[[.grp]])
        text(as.numeric(.grp), .range, labels=.range)

On 4/6/07, Daniel Siddle <sidds13 at hotmail.com> wrote:
> I am very new to R so forgive me if this seems basic but I have done extensive searching and failed to come up with the answer for myself.
> I am trying to label a boxplot I have created with the values for the median, upper and lower quartiles and max and min values.  I have been unable to do this or find anything on the net to say how it might be done.  Is this possible and if so how?  Regards,
> Daniel Siddle
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

More information about the R-help mailing list