R-断轴matplot功能

时间:2014-09-18 13:14:34

标签: r axis break

我需要将轴从0.5分到1.5。我的代码是:

matplot( wxyz$days_until_last_pay, wxyz[,c(2,3,4,5)], type=c("b"), pch=1, col=1:4,
         main="x![enter image description here][1]", cex.main=0.8)
legend("bottomright", inset=c(0,-0.57), fill=NULL, 
       legend = c("mean","median","max", "min"), col=1:4, pch=1, cex=0.8) 
library("plotrix")
axis.break(axis=2,1,,2,style="zigzag", brw=0.03)

但我只能在其中找到一条线。这不会破坏轴。 enter image description here

我该如何解决这个问题? 谢谢!

1 个答案:

答案 0 :(得分:0)

axis.break会对现有的plot进行分析,因此如果轴未“破坏”,则无效。

一个建议是将两个图形叠在一起并设置它们的ylim,使得在0.5和1.5之间存在间隙,例如

## Some data, set.seed(1)
dat <- matrix(c(rnorm(50, 2, 0.1),
              rnorm(50, 0.2, 0.05),
              rnorm(50, 0.3, 0.05)),
              byrow=FALSE, ncol=3)

## Split the device into two subplots
par(mfrow = c(2,1))

## Set the bottom margin of the top plot to 0.1
par(mar=c(0.1,4.1,4.1,2))

## Top plot (first column of the matrix)
plot(dat[,1], add=T, type="l", xaxt="n", ylab="", ylim=c(1.5, 2.5))

## Set the top margin of the bottom plot to 0.1
par(mar=c(5.1,4.1,0.1,2))

## Bottom plot
matplot(dat[,2:3], type="l", col=2:3, ylab="", ylim=c(0, 0.5))

这给你一些类似的东西: enter image description here