1

This is a sample of my data. It's a tab delimited file with a header.

X1      X2      X3      X4
1.3     0.5     0.1     1
NA      0.3     0.4     3
NA      0.2     0.3     0.3
NA      0.1     3       0.2
NA      27      5       56
NA      NA      10      0.01

I would like to get a boxplot from this data. The problem is that I want to interrupt the plot at 10 and 50 on Y-axis. I want a bigger plot size before 10 and a smaller plot size after that. I don't know how to plot with 2 gaps in Y-axis. I tried with axis.break and gap.boxplot but as my programming skills with R are very limited so I am unable to use both of these methods properly. I'd be grateful for any hints to accomplish this?

CassOnMars
  • 6,153
  • 2
  • 32
  • 47
vaqaar dar
  • 11
  • 1
  • 3

1 Answers1

1

I'm not really clear on what you want, and what you mean by "bigger plot size before 10 and a smaller plot size after that". Do you mean different scales? That is a bad idea, I think, and I don't believe it would be straightforward.

Here's how to break the axis twice (I'm guessing on the regions to exclude):

library(plotrix)
library(reshape2)
a <- read.table(textConnection("X1 X2 X3 X4
        1.3 0.5 0.1 1
        NA 0.3 0.4 3
        NA 0.2 0.3 0.3
        NA 0.1 3 0.2
        NA 27 5 56
        NA NA 10 0.01"),sep=" ",header=T)
am <-melt(a) #from reshape2 - allows categorical variables to be in one column
gap.boxplot(am$value ~ am$variable, #means the values are plotted againsy variable
gap=list(top=c(30,50),bottom=c(10,24)), #specifies regions of Y axis to exclude
axis.labels=T) #should label all the Y axis, doesn't seem to work well

enter image description here

alexwhan
  • 15,636
  • 5
  • 52
  • 66