Solved – Labeling boxplots in R

boxplotr

I need to build a boxplot without any axes and add it to the current plot (ROC curve), but I need to add more text information to the boxplot: the labels for min and max. Current line of code is below (current graph also).

Thanks a lot for assistance.

boxplot(data, horizontal = TRUE, range = 0, axes=FALSE, col = "grey", add = TRUE)

The other solution is add the line from 0 to 1 (instead of x-axis), but I want it to go through the central line…for example like this graphic

enter image description here

Best Answer

I think you will find this produces something like your hand-drawn diagram.

data    <- c(0.4, 0.7, 0.75, 0.82, 0.9)
endaxis <- c(0, 1)  # endpoints of axis
datamm  <- c(min(data), max(data))
boxplot(data, horizontal = TRUE, range = 0, ylim = endaxis,
                    axes = FALSE, col = "grey", add = FALSE)
arrows(endaxis, 1,  datamm, 1,  code = 1, angle = 90, length = 0.1)
valuelabels <- c(endaxis[1], round(fivenum(data)[2], digits = 2) ,
                 round(fivenum(data)[4], digits = 2), endaxis[2]  ) 
text(x = valuelabels, y = c(1.05, 1.25, 1.25, 1.05), labels = valuelabels)

R boxplot with value labels

There are probably better ways of doing it. You may need to adapt it to fit your ROC plot, including changing add = FALSE