zhanghao-njmu / SCP

An end-to-end Single-Cell Pipeline designed to facilitate comprehensive analysis and exploration of single-cell data.
https://zhanghao-njmu.github.io/SCP/
GNU General Public License v3.0
364 stars 80 forks source link

The angle parameter doesn't work in the theme function #235

Open Sophia409 opened 5 months ago

Sophia409 commented 5 months ago

Hello, SCP team,

I have an unresolved question and would appreciate your guidance.

Why does setting the angle parameter not work in the theme function? This question has puzzled me for a long time

FeatureStatPlot(myobject, stat.by = c("nFeature_RNA"), group.by = "celltype", palette = "Blues",stack = T,legend.position = 'none',theme_args = theme(axis.text.x = element_text(color="#993333",angle=90))) image

Thank you very much for your response.

Sophia

MInsYang commented 5 months ago

Hello, I am not part of the SCP team, but I have reviewed the SCP code. The cause of this issue may lie in the internal function ExpressionStatPlot being called by FeatureStatPlot. In terms of the usage of theme_args, the code includes: p <- p + do.call(theme_use, theme_args) + theme(aspect.ratio = aspect.ratio, axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)..., which means that when you set the angle of axis.text.x through theme_args in FeatureStatPlot, it will be overridden by the default settings of the function. Therefore, to achieve your desired effect, you can use FeatureStatPlot(myobject, stat.by = c("nFeature_RNA"), group.by = "celltype", palette = "Blues", stack = T, legend.position = 'none', theme_args = theme(axis.text.x = element_text(color="#993333"))) + theme(axis.text.x = element_text(angle = 90)) or directly set the theme after obtaining the ggplot object from FeatureStatPlot like FeatureStatPlot(myobject, stat.by = c("nFeature_RNA"), group.by = "celltype", palette = "Blues",stack = T,legend.position = 'none')+ theme(axis.text.x = element_text(color="#993333",angle=90))