Change transparency/alpha in seurat's vlnPlot()
1
0
Entering edit mode
15 months ago

Hello,

I would like to change the transparency of my violin plots in Seurat. It should be simple yet it seems there isn't a function for this? This is the original code:

VlnPlot(object = obj, features = 'features', split.by = "Group")

and then I tried to use ggplot as I normally do with my sce object:

gg<-VlnPlot(object = obj, features = 'features', split.by = "Group")

gg + geom_violin(aes(fill = "gray", alpha = 0.5)) +
  theme_minimal() +
  ylab("text1") +
  xlab("text2")

But it just added a third violin that was indeed transparent over the top of the other two plots. Surely there is a 'alpha = ' equivalent in Seurat?

Thank you for your help!

seurat violin-plot • 2.4k views
ADD COMMENT
1
Entering edit mode

You can not just add a geom_violin() to the previous VlnPlot object and expect it to change. You have two options, one is to go find the source code for the VlnPlot (on GitHub here) and then copy the function (and other functions it depends on like ExIplot()) and then add your alpha argument to its geom_violin and run it on your local session; OR you can just do a simple violin plot yourself by exporting the data you want from Seurat object into a dataframe format readable by ggplot. To export the data you must know which subset of the obj you are interested in see here as a example.

ADD REPLY
0
Entering edit mode

Thank you, yes that's what I'v done in the end and have it working now. Strange seurat vlnPlot doesn't have that as an option already!

ADD REPLY
1
Entering edit mode
15 months ago
fracarb8 ★ 1.7k

You can change the alpha values of the filling inside scale_fill_manual (same applies for scale_colour_manual)

colori <- viridis(5, alpha = 1, begin = 0, end = 1, direction = -1, option = "viridis")
VlnPlot(exp_Integrated,"CD8A", pt.size = 0) +  scale_fill_manual(values = colori)

enter image description here

VlnPlot(exp_Integrated,"CD8A", pt.size = 0) +  scale_fill_manual(values = alpha(colori , 0.3))

enter image description here

When you split things get a bit weird as sometimes the changes are applied only to the last element of the returned list (1 element for every plot). If that happens you can iterate to the list and add scale_fill_manual to all the elements of the list or you can for some setting in patchwork.

ADD COMMENT

Login before adding your answer.

Traffic: 2634 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6