satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.24k stars 902 forks source link

Text does not appear in DarkTheme in FeaturePlot #1361

Closed fly4all closed 5 years ago

fly4all commented 5 years ago

I tried applying dark theme onto my tSNE feature plot but it seems that font might still be black in color and so, I'm unable to see it with the dark background. Is there any fix for this?

Code: baseplot <- FeaturePlot(object=decoder, features= features, reduction='tsne', pt.size=0.1) baseplot + DarkTheme()

Screen Shot 2019-04-11 at 1 02 07 PM
mojaveazure commented 5 years ago

Hi Maria,

This is happening because CombinePlots using cowplot::plot_grid which disables modifying individual plot components. CombinePlots is automatically called when plotting multiple features to keep everything together nicely.

To get around this, pass combine = FALSE to FeaturePlot, modify your plots in a for-loop or with lapply, then call CombinePlots to stitch everything together for you.

baseplot <- FeaturePlot(object = decoder, features = features, reduction = 'tsne', pt.size = 0.1, combine = FALSE)
for (i in 1:length(x = baseplot) {
  baseplot[[i]] <- baseplot[[i]] + DarkTheme()
}
# Can also use lapply
baseplot <- lapply(
  X = baseplot,
  FUN = function(p) {
    return(p + DarkTheme())
  }
)
CombinePlots(plots = baseplot, ncol = 2)
fly4all commented 5 years ago

Hi Paul,

Thank you for the quick response. I tried both the methods but it gives me an error.

Upon doing it with for loop:

Error in baseplot[[i]] + DarkTheme() : 
  non-numeric argument to binary operator
In addition: Warning message:
In baseplot[[i]] + DarkTheme() :
  Incompatible methods ("Ops.data.frame", "+.gg") for "+

Upon running the lapply method (I have always run into an error trying to run combinePlots, I'm not sure why):

> baseplot <- lapply(
+   X = baseplot,
+   FUN = function(p) {
+     return(p + DarkTheme())
+   }
+ )
Error in p + DarkTheme() : non-numeric argument to binary operator
In addition: Warning message:
In FUN(X[[i]], ...) :
  Incompatible methods ("Ops.data.frame", "+.gg") for "+"
> CombinePlots(plots = baseplot, ncol = 2)
Error in plot_to_gtable(x) : 
  Argument needs to be of class "ggplot", "gtable", "grob", "recordedplot", or a function that plots to an R graphicsdevice when called, but is a data.frame
mojaveazure commented 5 years ago

Hi Maria,

You need to rerun FeaturePlot and pass combine = FALSE like I said above.

fly4all commented 5 years ago

Oh, sorry I missed on that. It works now, thank you!

ondina-draia commented 2 years ago

The only problem remaining is that the cluster labels are still black

samuel-marsh commented 2 years ago

@ondina-draia just submitted PR #5314 to add this parameter to FeaturePlot (already possible in DimPlot).

Best, Sam

ondina-draia commented 2 years ago

@samuel-marsh This is wonderful, thank you 😊