rboxplotplotrix

How to display a boxplot with a missing y-axis range using gap.boxplot (base r)? (almost there, struggling with an error)


I want to create a nice boxplot with this dataset:

data_N3_minmax = structure(c(2.71177214885543, 4.36849175181861, 17.626304994383, 
17.7213767231357, 1116.19429181322, 1121.5558117271, NA, NA, 
5.54438655223586, 15.5774104850416, 7.34658260987168, 25.2590667564114, 
8.44869502735733, 17.5713360077048), .Dim = c(2L, 7L)) 

I first used this code:

label=c("V1", "V2", "V3", "V4", "V5", "V6", "V7")

boxplot(data_N3_minmax, xlab="", ylab="", names=label)

This code produces this graph: enter image description here

You see that there is a huge difference between V3 and the rest. Therefore, I wanted to incorporate an y-axis gap. I started with the gap.boxplot function from the package plotrix. However, I ran into a problem that I don't know how to fix. I used this code:

library("plotrix")

label=c("V1", "V2", "V3", "V4", "V5", "V6", "V7")

gap.boxplot(data_N3_minmax, gap=list(top=c(30,1000), bottom=c(NA,NA)), xlab="", ylab="", names=label)

I only want to get one gap between the values of V3 and the other boxplots, so I do not use the bottom gap. Sadly, I got this error message: Error in gap.boxplot(data_N3_minmax, gap = list(top = c(50, 1000), bottom = c(NA, : gap cannot include the median, interquartiles or the staples.

This confuses me because the gap I want to include (between 30 and 1000) does not include the median, interquartiles or the staples. Can anyone help me to solve this problem or show me how I can incorporate an axis gap in another way? I mostly have experience with base R plotting and no experience with ggplot, so I would prefer to do this in base R.


Solution

  • It's the all-NA column no. 4 which raises the error. Leaving it out will work:

    
        gap.boxplot(data_N3_minmax[, -4],
                    gap=list(top=c(30,1000), bottom=c(NA,NA)) #, ...
                    )
    
    

    omit all-NA variables saves gap boxplot

    edit

    sort of hackish solution to keep an empty seat for variable no. 4:

        data_N3_minmax[,4] <- 0
    
        gap.boxplot(data_N3_minmax,
                    border = c(rep(TRUE,3), NA, rep(TRUE, 3)),
                    gap = list(top=c(30,1000), bottom=c(NA,NA))
                    )