Boxplot emission marking in R

I want to draw boxes in R and add names to outliers. So far I have found this solution .

The function there provides all the functionality I need, but it incorrectly crosses labels. In the following example, he marks outlier as "u" instead of "o":

library(plyr)
library(TeachingDemos)
source("http://www.r-statistics.com/wp-content/uploads/2011/01/boxplot-with-outlier-label-r.txt") # Load the function
set.seed(1500)
y <- rnorm(20)
x1 <- sample(letters[1:2], 20,T)
lab_y <- sample(letters, 20)
# plot a boxplot with interactions:
boxplot.with.outlier.label(y~x1, lab_y)

Do you know of any solution? The ggplot2 library is very beautiful, but does not provide such functionality (as far as I know). My alternative is to use the text () function and extract the emission information from the boxplot object. However, such marks may overlap.

Many thanks: -)

+5
source share
2 answers

debug(boxplot.with.outlier.label) ... bug.

125, data.frame DATA x, y label_name.

x y , lab_y . x ( x1) , .

, x, ( - )

df <- data.frame(y, x1, lab_y, stringsAsFactors=FALSE)
df <- df[order(df$x1), ]
# Needed since lab_y is not searched for in data (though it probably should be)
lab_y <- df$lab_y  

boxplot.with.outlier.label(y~x1, lab_y, data=df)

Boxplot produced by procedure described above

+6

- , . , .

, :

set.seed(1501)
y <- c(4, 0, 7, -5, rnorm(16))
x1 <- c("a", "a", "b", "b", sample(letters[1:2], 16, T))
lab_y <- sample(letters, 20)

bx <- boxplot(y~x1)

out_lab <- c()
for (i in seq(bx$out)) { 
    out_lab[i] <- lab_y[which(y == bx$out[i])[1]]
}

identify(bx$group, bx$out, labels = out_lab, cex = 0.7)

, identify(), , , . "STOP". , ! !

PS: for, , - .

EDIT: Federico link , ! :

boxplot(y~x1)
identify(as.integer(as.factor(x1)), y, labels = lab_y, cex = 0.7)
+1

All Articles