1

There are easy ways to make axis breaks/gap plots. Is there a similarly simple way to make a axis break/gap plot with error bars? (I know only fiddly ways)

# install.packages("plotrix", dependencies = TRUE)
require(plotrix)     

x <- c(1:20); y <- c(rnorm(10)+4, rnorm(10)+20)
gap.plot(x,y, gap=c(8,16), ytics=c(1:8,16:25))

enter image description here

errorbars <- function(x, y, err, width){
  x0 = x; y0 = (y-err)
  x1 = x; y1 = (y+err)
  arrows(x0, y0, x1, y1, code=3, angle=90, length=width)
}

err <- rep(1,20)
plot(x,y)
errorbars(x,y,err,0.05)

enter image description here

Eric Fail
  • 8,191
  • 8
  • 72
  • 128
ckluss
  • 1,477
  • 4
  • 21
  • 33
  • 3
    There are only "fiddly ways" because data viualization expert don't approve of axis breaks. Rightly so. – Roland Aug 01 '14 at 07:43
  • 1
    Look for `plotrix::gap.plot`, but more importantly, what @Roland said. – Thomas Aug 01 '14 at 10:48
  • thx, and there is a gap.plot example in my question ;) but how I can do errorbars within gap.plot? – ckluss Aug 01 '14 at 13:21

1 Answers1

0

What @Roland said.

I would suggest a solution where you put it all on a logarithmic scale. Like this (See below for code). To the left is the one on a logarithmic scale and to the right is the one on a standard linear scale for comparison.

enter image description here

# install.packages("ggplot2", dependencies = TRUE)
require(ggplot2)
# data(mtcars) # add this if you rerun it to get a clean `mtcars`
mtcars$cyl2<- ifelse(mtcars$cyl > 4, c('A'), c('B')) 
# multiplying cylenders for B by 10
mtcars$mpg[mtcars$cyl2=='B'] <- mtcars$mpg[mtcars$cyl2=='B'] * 10
p <- ggplot(mtcars, aes(factor(cyl), mpg))
p1 <- p + geom_boxplot() + facet_grid(. ~ cyl2, scales = "free", space = "free") + scale_y_log10() + labs(title = "On a logarithmic scale")
p2 <- p + geom_boxplot() + facet_grid(. ~ cyl2, scales = "free", space = "free") + labs(title = "On a standard linear scale")

# install.packages("gridExtra", dependencies = TRUE)
require(gridExtra)

grid.arrange(p1, p2, ncol=2)
Eric Fail
  • 8,191
  • 8
  • 72
  • 128