简体   繁体   English

中断绘图中的x轴

[英]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. 我想破坏使用函数plot.stepfun的累积分布函数的图的x轴,但似乎无法弄清楚该怎么做。

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: 然后,我使用函数ecdf获得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). 我之类的改变x.cdf到stepfun,因为我更愿意称plot.stepfun直接在使用plot.ecdf (也使用plot.stepfun ,但机会比较少定制的情节)。

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. 但是现在我想将x轴分解为12到20之间,例如使用axis.break [plotrix-library],例如here ,但是由于我没有用于绘制的普通x和y参数,所以我不知道如何去做这个。

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". 对我而言,“在12到20之间断开轴”没有太大意义,因为20是x范围的终点,因此我将举例说明在12到15之间断开轴。plotrix.axis.break函数不会实际上确实做了很多(如果您逐步看一下该示例,就可以看到。)它所做的只是在特定位置(“ 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. 所有其余的工作都需要使用常规的绘图功能完成,并且plot.stepfun并未真正做到这一点,因此我将使用带有type =“ s”参数的常规plot.default。 You need to do the offsetting of the x values, the arguments to the ecdf function and the labels in the axis arguments. 您需要对x值,ecdf函数的自变量以及轴自变量中的标签进行偏移。

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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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