davismcc / archive-scater

An archived version of the scater repository, see https://github.com/davismcc/scater for the active version.
64 stars 18 forks source link

plotExpression x-axis labels #118

Closed julien-roux closed 7 years ago

julien-roux commented 7 years ago

Hi Davis, I want to plot the expression of a subset of genes of interest using the plotExpression function. However the default labels are Ensembl IDs (the feature names in my SCESet object) which are not easy to decipher... I have a symbol column in the featureData of my SCESet object and I would like to use this as x-axis label.

The intuitive command to run seems to be:

plotExpression(sce, myGenes, x="symbol", alpha=0.2) + fontsize

However I get this error:

Error in plotExpressionSCESet(object, ...) : 
  'x' should be a column of pData(object) or in featureNames(object)

My feeling is that x should be a column of fData(object) not pData(object).

Is that an error?

davismcc commented 7 years ago

Hi Julien

As the docs for plotExpression state, the x argument is used to give cell variable (cell metadata or feature expression) to use on the x-axis of the plot (e.g. so you can plot feature expression against total features, or expression of gene 1 against expression of gene 2). Each point on the plot represents a cell, so it does not make sense for x to be a column of fData(object).

However, if you don't specify x then you get the violin plots for a set of genes. I think this is what you're getting at. There's no argument to change the x-labels, so there are two options:

  1. Replace existing featureNames with symbols (e.g. featureNames(object) <- fData(object)$symbol - obviously, symbols need to be unique for this to work.

  2. Use the capabilities of ggplot2 - the output of plotExpression is a ggplot object, so many ggplot manipulations work. e.g. plotExpression(object, myGenes) + scale_x_discrete(labels = fData(object)[myGenes, "symbol"])

Hope that helps Davis

julien-roux commented 7 years ago

Great!

I had tried something like solution 1, but the symbols are indeed not unique, so some tweaking was needed...

Solution 2 works just fine, thanks for that!

Julien