7
$\begingroup$

FeaturePlot is a function in Seurat package.

And in the vignette it is written that if we specify parameter do.return = TRUE it should return ggplot2 object. It is not working. My goal here is just to change the title of the plot. In case of violin plot I can do the following:

VlnPlot(object = seurat_object, features.plot = id, do.return = TRUE) + labs(title = endothelial_symbols[1])

But with FeaturePlot similar code fails to work:

FeaturePlot(object = seurat_object, features.plot = id, cols.use = c("grey", "blue"),
                          reduction.use = "tsne", do.return = TRUE) + labs(title = endothelial_symbols[1])

Giving the error:

Error in FeaturePlot(object = seurat_object, features.plot = id, cols.use = c("grey", : non-numeric argument to binary operator

Any suggestions would be greatly appreciated.

$\endgroup$

1 Answer 1

3
$\begingroup$

I tried with some data that I have and this is working for me:

p <- FeaturePlot(object = seurat_object, features.plot = id, cols.use = c("grey", "blue"),
                      reduction.use = "tsne", do.return = TRUE)


lapply(p, function(x){x + labs(title = endothelial_symbols[1])})

I think it is because FeaturePlot returns several ggplot objects according to the ids you put. This is returned as a list of plots so you have to iterate each one for labeling.

$\endgroup$
1
  • 1
    $\begingroup$ This can be “simplified” to lapply(p, `+`, labs(title = endothelial_symbols[1])). $\endgroup$ Commented Jun 13, 2018 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.