kuwisdelu / Cardinal

Mass spectrometry imaging toolbox
http://www.cardinalmsi.org
36 stars 14 forks source link

Cannot pass for loop variables to image() #6

Closed DennisJakob closed 5 years ago

DennisJakob commented 5 years ago

Hi,

I used to plot images with the following code (edited example) passing the mz argument to the image function via a for loop. par(mfrow = c(2,2), mar = c(5, 5, 5, 5), oma = c(0, 0, 5, 0), cex = 0.8) for (i in 400:403) { image(msi, mz = i, plusminus = 0.001, col.regions = inferno(n = 100), colorkey = TRUE) I wanted to change my script using Cardinal v2.2.6 and it seems like the mz argument of the image function does not take the variable of the for loop anymore. I know that you implemented the layout function now, but I need to use the par(mfrow=) function to add further labels (e.g. compound name, adduct) to the image. Is there a way to still pass mz via a for loop variable? If this example is not clear enough I can attach my files.

Cheers, Dennis

DennisJakob commented 5 years ago

I just figured out that it is working for MSImageSet format but not for MSImagingExperiment. Do you know why that is? You probably won't update the image() function for the old MSImageSet format right? Do have any suggestions how to workaround this issue?

kuwisdelu commented 5 years ago

Please try print(image(msi, mz = i, ...))

Similar to graphics from the lattice and ggplot2 packages, the plot() and image() methods in Cardinal now produce printable objects rather than plotting anything themselves.

This allows for greater flexibility and modularity in the implementation (as well as the ability to store plots as variables) but requires explicitly print()-ing the plots whenever print() wouldn't be called implicitly (such as in the body of a for loop).

Please let me know if this doesn't work.

kuwisdelu commented 5 years ago

Also, if you want to control the layout yourself, you may want to include layout=FALSE or layout=NULL (they do the same thing) in your call to make sure the auto-layout is suppressed.

Note also that the strip labels have moved to using mtext() to create a title outside the plotting space rather than the old translucent legend inside the plot, which may interfere with your manual labels. You may want to turn them off with strip=FALSE if you are creating manual labels. You can also move them to the old location with strip=list(oldstyle=TRUE).

kuwisdelu commented 5 years ago

There are no plans to change or update any of the methods for MSImageSet.

DennisJakob commented 5 years ago

Thanks a lot! The print() was exactly what I needed.