简体   繁体   中英

Break x-axis in plot

I want to break the x-axis of a plot of a cumulative distribution function for which I use the function plot.stepfun , but don't seem to be able to figure out how.

Here's some example data:

set.seed(1)
x <- sample(seq(1,20,0.01),300,replace=TRUE)

Then I use the function ecdf to get the empirical cumulative distribution function of x:

x.cdf <- ecdf(x)

And I change the class of x.cdf to stepfun, because I prefer to call plot.stepfun directly over using plot.ecdf (which also uses plot.stepfun , but has fewer possibilities to customize the plot).

class(x.cdf) <- "stepfun"

Then I am able to create a plot as follows:

 plot(x.cdf, do.point=FALSE)

But now I want to break up the x-axis between 12 and 20, eg using axis.break [plotrix-library] such as here , but since I have no ordinary x and y-argument for plotting, I don't know how to do this.

Any help would be very much appreciated!

"Breaking the axis between 12 and 20" doesn't make a lot of sense to me since 20 is the end of the x range, so I will exemplify breaking it between 12 and 15. The plotrix.axis.break function doesn't actually do very much (as can be seen if you step through that example.) All it does is put a couple of slashes at a particular location, the "breakpos". All the rest of the work needs to be done with regular plotting functions and plot.stepfun isn't really set up to do it, so I'm using regular plot.default with the type="s" argument. You need to do the offsetting of the x values, the arguments to the ecdf function and the labels in the axis arguments.

png()
 plot( c(seq(1,12,0.1), seq(15,20,0.1)-3),  # Supply the range, shifted
         x.cdf(c(seq(1,12,0.1), seq(15,20,0.1))),  # calc domain values, not shifted
         type="s",  xaxt="n", xlab="X", ylab="Quantile")
 axis(1, at=c( 1:12, (16:20)-3), labels=c(1:12, (16:20)) ) #shift x's, labels unshifted
 axis.break(breakpos=12)
dev.off()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM