Hi satijalab,
I've noticed unexpected behavior when I plot metadata in Seurat3 using FeaturePlot. Specifically, I have a metadata slot called "VIPER_Activity" which contains continuous data in the range approximately (-2.5, +2.5). When I plot these data with FeaturePlot without specifying the color:
FeaturePlot(data, features = "VIPER_Activity")
I get the expected output which has a color scale (-2.5, +2.5). If I use custom colors, though the color scale seems to take the index-value of the color array it is contained in:
FeaturePlot(data, features = "VIPER_Activity", cols = rev(brewer.pal(n = 11, name = "RdBu")))
I've solved this issue by using ggplot directly on the data, but seems to me like it's not the desired behavior by your function.
Thanks for your great work on this package - it's super useful and clean!
Hi @AidanQuinn ,
Sorry if the cols parameter is a bit unclear as it tries to handle a lot of cases (specifically w.r.t the blend functionality). If you want a continuous gradient scale like that, you can provide the colors corresponding to the min and max and it will create the scale based off those. E.g.
FeaturePlot(pbmc_small, "LYZ", cols = c("red", "blue"))
However, a solution probably closer to what you want with RdBu would be to add the continuous color scale as you would for any ggplot object. E.g.
FeaturePlot(pbmc_small, "LYZ") + scale_colour_gradientn(colours = rev(brewer.pal(n = 11, name = "RdBu")))
Hi @AidanQuinn ,
Sorry if the
colsparameter is a bit unclear as it tries to handle a lot of cases (specifically w.r.t the blend functionality). If you want a continuous gradient scale like that, you can provide the colors corresponding to the min and max and it will create the scale based off those. E.g.FeaturePlot(pbmc_small, "LYZ", cols = c("red", "blue"))However, a solution probably closer to what you want with
RdBuwould be to add the continuous color scale as you would for any ggplot object. E.g.FeaturePlot(pbmc_small, "LYZ") + scale_colour_gradientn(colours = rev(brewer.pal(n = 11, name = "RdBu")))
Yeap, that's more or less what I did. Totally makes sense why it's happening, just an unexpected behavior from my end. Thanks!
Hi @andrewwbutler
your proposed workaround works nicely if a single feature is plotted. However, when adding a list/vector of various features the function scale_color_gradient() just changes the color of the last plot. I guess this is due to the usage of patchwork. Any idea how to change the color scale for all plots within the plot arrangement?
Thanks for developing Seurat and best wishes,
Christian
Hi @christianholland ,
If you want to apply the scale to all the plots, you need to use the & operator instead. E.g.
FeaturePlot(pbmc_small, c("LYZ", "MS4A1")) &
scale_colour_gradientn(colours = rev(brewer.pal(n = 11, name = "RdBu")))
This was actually one of the reasons we switched to patchwork was being able to easily add themes/scales/etc to these kind of composite ggplot objects. For more details on this topic, please see the patchwork docs (particularly the "Modifying everything" section here).
Great, thanks for pointing to this feature of patchwork
Most helpful comment
Hi @christianholland ,
If you want to apply the scale to all the plots, you need to use the
&operator instead. E.g.This was actually one of the reasons we switched to patchwork was being able to easily add themes/scales/etc to these kind of composite ggplot objects. For more details on this topic, please see the patchwork docs (particularly the "Modifying everything" section here).