2

I am using the function plotMDS() of package limma that makes a plot by the simple plot() format of R, and also returns the position of the points on the plot as output. I want to use the output of plotMDS() to produce my own beautiful plot.

Is there any way to run plotMDS() without having it's plot really generated? The reason I ask so is that I have already casted the output to a PDF file and I don't want the original plot of the plotMDS() to be there!

Ali
  • 9,440
  • 12
  • 62
  • 92
  • 1
    maybe open another device and use `dev.next`/`dev.set` etc. to switch over to the other device and back again. – Ben Bolker Nov 08 '12 at 22:50
  • 1
    As it stands this question is very vague. How about a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) - What package? – mnel Nov 08 '12 at 22:51
  • 1
    How can anyone answer without knowing what the function/package is? – joran Nov 08 '12 at 22:53
  • Why not just capture the output of the plot outside the pdf call and then create whatever graphics you want for the pdf? – mnel Nov 08 '12 at 23:03
  • @mnel Because there is a sequence of many plots to be created, I have already opened pdf file long time ago. – Ali Nov 08 '12 at 23:06
  • @joran I believe providing the name of function/package is not necessary here, as my question is general and other people running other functions of other packages may have some similar question some day – Ali Nov 08 '12 at 23:07
  • Make your example reproducible (including your workflow) and perhaps you will get a useful answer. – mnel Nov 08 '12 at 23:09
  • Functions within packages can do many weird and wonderful things in nonstandard ways. @joran is spot on, your answer (and any similar problem) will be *entirely* dependent on the internal workings of the function. – mnel Nov 08 '12 at 23:11
  • @BenBolker Great! the problem was solved by dev.new() and dev.off() before and after. Why don't you make your comment as answer to be accepted? – Ali Nov 08 '12 at 23:13

2 Answers2

5

Thanks @BenBolker, it can be done like this:

pdf("Some file")
...
dev.new() # Putting new plots to nowhere
mds <- plotMDS(data)
dev.off() # Restoring new plots to the PDF file
plot(...) # Making the desired plot using mds
...
dev.off() # Closing PDF file
Ali
  • 9,440
  • 12
  • 62
  • 92
2

Looking at your answer it seems like this might be a reasonable alternative:

mds <- plotMDS(data)
pdf("Some file")
...
plot(...) # Making the desired plot using mds
...
dev.off() # Closing PDF file

I don't know exactly what you're doing but if you're interested in reproducible documents then you could also use the knitr package to create your output. It would be very easy to suppress a single plot and then plot later using knitr.

Dason
  • 60,663
  • 9
  • 131
  • 148
  • Thanks, but as I informed in the comments there is a sequence of many commends to be run, and many charts to be created. So I have to make the PDF first (for the earlier charts) and compute the plotMDS later – Ali Nov 09 '12 at 15:10