如何减少R中的轴刻度和轴标签之间的空间

cha*_*has 3 curve r

我在R中生成以下图:

码:

ecdf.bdel<-ecdf(bDE[,6])  #### cumulative distribution of a vector of numeric values

curve(1-ecdf.bdel(x),col="red",xlim=r,xlab="r2",ylab="Fraction of SVs tagged") ###plotting inverse ecdf curve
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

该情节是预期的。但是,它在轴刻度和轴标签之间以及轴标签和轴实验室之间留有巨大的空白。

有人可以提供任何技巧来减少空白。

Sow*_*ian 7

mgp像这样插入参数,看看它是否有效。另请参阅mar参数的所有方面。您可以在par()函数内部同时使用这两个函数来解决您的问题。

   par(mgp=c(3,1,0),mar(5,4,4,2)+0.1)
   curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged") 
Run Code Online (Sandbox Code Playgroud)

firstin中的值mgp表示您axis labels在靠近或远离轴的位置移动,较小的值表示靠近轴,较高的值表示在两个轴(即x和y轴)上都远离轴。

中的secondmgp表示您的tick labels移动接近或远离刻度,较小的值表示靠近刻度,而较高的值表示在两个轴(即x和y轴)上都远离刻度。

thirdin中的值mgp是您ticks移动到靠近或远离轴线本身的位置,较小的值表示靠近轴线,而较高的值表示两个轴线都远离轴线,即x和y。

mar是形式为数字的矢量,c(bottom, left, top, right)它给出要在图的四个边上指定的边距线数。默认值为c(5, 4, 4, 2) + 0.1

xlimcurve()功能中删除。您的图形条件

  par(mgp=c(10,4,0),mar=c(11,11,5,5)+0.1)
  curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged") 
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

 par(mgp=c(3,1,0),mar=c(5,4,4,2)+0.1)
 curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged") 
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

示例:使用plot代替曲线。相似

第一种情况:

    par(mgp=c(7,3,0),mar=c(8,8,5,5)+0.1)
    plot(1:10,xlab="X Axis", ylab="Y Axis", main="My Plot")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

第二种情况

    par(mgp=c(3,1,0),mar=c(5,4,4,2)+0.1)
    plot(1:10,xlab="X Axis", ylab="Y Axis", main="My Plot")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明