2

TL;DR: I'm getting the above (and below) error. How do I fix it?

Since I'm relatively new to R, this has me stumped. I'm trying to create an xyplot where both the axes are log-transformed. I've gotten this far:

library(lattice)
xyplot(`APC-H7-A`~`PE-Cy5-A`,lymphocytes, smooth=FALSE, 
       xlim=c(-100,10000), ylim=c(-100,10000),
       scales=list(x=list(log=10),y=list(log=10)))

And I keep getting an error:

Error in Math.factor(x, xbase) : ‘log’ not meaningful for factors

I'm guessing that the error means something in my code isn't recognised as a number? but I don't really know where to start looking.

Lymphocytes is an object of flowFrame class, within the flowCore package:

Description. This class represents the data contained in a FCS file or similar data structure. There are three parts of the data:*

  • A numeric matrix of the raw measurement values with rows=events and columns=parameters
  • Annotation for the parameters (e.g. the measurement channels, stains, dynamic range)
  • Additional annotation provided through keywords in the FCS file*
David C.
  • 1,974
  • 2
  • 19
  • 29
Shieldsy
  • 23
  • 2
  • 3
    Are APC-H7-A and/or PE-Cy5-A by any chance... factors? Please provide enough details for us to either reproduce (`dput()`) or give an educated guess (`str()`) of what's going on. – Roman Luštrik Feb 10 '17 at 08:36
  • Related, possible duplicate of http://stackoverflow.com/questions/30525292 – zx8754 Feb 10 '17 at 08:52
  • are the 2 selected columns numeric? what if you try `as.numeric`? `xyplot(as.numeric(lymphocytes$'APC-H7-A') ~ as.numeric(lymphocytes$'PE-Cy5-A'), smooth = FALSE, ...)` – deeenes Feb 11 '17 at 23:22
  • No the columns aren't numeric (but they aren't vectors either). deeenes answer, and my reply, give a bit more detail. Though `as.numeric` will probably be really useful too. – Shieldsy Feb 12 '17 at 22:05

1 Answers1

1

This is a complex data structure and it is not straightforward to access the raw data. The manual page of flowFrame (see help(flowFrame)) says that we can index this object, and with the exprs method is the way to the raw data. Also this class has its own plotting methods, I assume you have a good reason why you choose lattice instead. With loading the example data the way below I could run your plotting code:

require(flowCore)
require(lattice)
data(GvHD)

xyplot(exprs(GvHD[[1]][, "FL4-H"]) ~ exprs(GvHD[[1]][, "FL2-H"]),
        smooth=FALSE,
        xlim=c(-100,10000),
        ylim=c(-100,10000),
        scales=list(x=list(log=10),
                    y=list(log=10)),
        xlab = "FL2-H",
        ylab = "FL4-H")

I don't know what is FL2-H, FL4-H and index 1 in this data array, but I am sure you will find out quickly as you know your data.

deeenes
  • 4,148
  • 5
  • 43
  • 59
  • Oh! I see now. I've been using a package called flowViz for my plotting, and I had been using their implementation of lattice xyplot as opposed to actual lattice. I'd just been assuming they were the same thing because the function name was the same -.- stupid mistake. Question though: why does the format of the data (numerical, vector, etc) matter if the logarithm is only to be applied to the scale? Shouldn't this be independent of the data? – Shieldsy Feb 12 '17 at 22:01
  • that is definitely not independent from the data, as the value of each data point along that scale need to be logarithm transformed in order to get the coordinate of that point on the plot. just try for example `log(as.factor(c(1,2,3)))`, and you will get the same error as in your question – deeenes Feb 12 '17 at 23:57
  • note: if you have methods with identical names from different packages, the one loaded later masks the other. usually you get a message about this at loading the package. you can be sure that you access the method from the package you want by using double colons: `lattice::xyplot(...)` – deeenes Feb 13 '17 at 00:02
  • Thanks. I realised that my data is already transformed, and that the reason my plots looked skewed is that there were outliers skewing the way my data was handled at another stage -.- I just assumed that I had to transform the axes because the tick marks were labelled in linear. – Shieldsy Feb 13 '17 at 07:09