5

I have the below plot generated in R:

Code:

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

enter image description here

the plot is as expected. However, it leaves huge white space between axis ticks and axis labels and also between axis labels and axis labs.

Could someone offer any tip to reduce the white space.

chas
  • 1,565
  • 5
  • 26
  • 54
  • does using `plot(inv,type="l",col="red",xlim=r,xlab="r2",ylab="Fraction of SVs tagged")` solve the problem? You can define `inv<-1-ecdf.bdel(x)` the points you want to plot. – Waqas Aug 13 '16 at 18:29
  • using plot gives the error: `Error in .approxfun(x, y, v, method, yleft, yright, f) : object 'x' not found` – chas Aug 13 '16 at 18:32
  • Is it possible if I could replicate your plot in my machine?I can then try. – Waqas Aug 13 '16 at 18:34
  • here is the sample file ~70kb in size (http://www.fileconvoy.com/dfl.php?id=g30af57873c71463e9998641601e872a181d43d80f) . Basically, i am trying to plot inverse cumulative frequency plot of the values in column 1 in the file. – chas Aug 13 '16 at 18:39
  • sorry for confusing. I mean complementary cumulative distribution funciton plot – chas Aug 13 '16 at 18:52
  • I checked again it works fine on my machine by removing `xlim=r` and reading the file in my way. – Waqas Aug 13 '16 at 19:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120880/discussion-between-vic-and-chas). – Waqas Aug 13 '16 at 19:25
  • `ecdf.bdel<-ecdf(bDE[,6])` #### cumulative distribution of a vector of numeric values Is the 6th column the frequency of the V1 values? – Sowmya S. Manian Aug 13 '16 at 19:41
  • ok You can download the plot and use it!I hope all is solved now? – Waqas Aug 13 '16 at 20:38

2 Answers2

16

Insert mgp parameter like this, and see if it works. Also see mar parameter for margin from all the sides. You can use both together inside par() function to solve your problem.

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

The first value in mgp is where your axis labels moves either close to or far from axis, less value means closer to axis and high value means far from axis on both the axis i.e. x and y axis.

The second value in mgp is where your tick labels moves either close to or far from ticks, less value means closer to tick and high value means far from ticks on both the axis i.e. x and y axis.

The third value in mgp is where your ticks moves either close to or far from axis line itself, less value means closer to axis line and high value means far from axis line on both the axis, i.e. x and y.

mar is a numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is c(5, 4, 4, 2) + 0.1.

Remove xlim from curve() function. Your graph condition

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

enter image description here

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

enter image description here

Example: Using plot instead of curve. It is similar

First Case:

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

enter image description here

Second Case

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

enter image description here

Sowmya S. Manian
  • 3,723
  • 3
  • 18
  • 30
  • for some reason i end up having the similar plot, no matter what the mpg and mar values are!!! – chas Aug 13 '16 at 19:27
  • Could you please share your entire code for this plot? We have the data and please add `sessionInfo()` so that we know which machine you are using. – Sowmya S. Manian Aug 13 '16 at 19:30
  • The below three steps should work. `>ecdf.bdel<-ecdf(df[,1]) ` `>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")` – Sowmya S. Manian Aug 13 '16 at 19:32
  • 1
    it worked. but how can save it as png with 300dpi resolution? – chas Aug 13 '16 at 19:44
  • `>png("Plot.png", width = 4, height = 4, units = 'in', res = 300)` `>ecdf.bdel<-ecdf(df[,1])` `>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")` `>dev.off()` – Sowmya S. Manian Aug 13 '16 at 19:50
  • add the first and last command i.e. `png()` and `dev.off()` and in between would be your code like shown in above comment. Then check your current working directory, that will have your png file. – Sowmya S. Manian Aug 13 '16 at 19:51
0

enter image description hereIs this what you want? I had no other option to show the plot I will add the code if this is what you want.

This is what I did:

data<-read.table("Ld.txt",F)
ecdf.bdel<-ecdf(data$V1)  #### cumulative distribution of a vector of numeric values

curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged") ###plotting inverse ecdf curve

enter image description here

Waqas
  • 329
  • 3
  • 16
  • i don't see any difference in the code with mine. however i am having this wierd space issue between the axis and labels. – chas Aug 13 '16 at 19:03
  • I removed the xlim. Just try on the file, it should work. Also maybe possible problem with how you were reading the file. I used V1, by saying F in `read.table` – Waqas Aug 13 '16 at 19:03
  • No problem! Happy I was of some use. – Waqas Aug 13 '16 at 19:17
  • i was too early to post that it worked. Either solutions give me the plot with the space issue. The problem still holds – chas Aug 13 '16 at 19:23
  • Did you remove the `xlim` ? – Waqas Aug 13 '16 at 19:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120881/discussion-between-vic-and-chas). – Waqas Aug 13 '16 at 19:29