Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to customize the order of groups within the FeatureStatPlot function #245

Open
jphe opened this issue Jun 19, 2024 · 3 comments
Open

Comments

@jphe
Copy link

jphe commented Jun 19, 2024

Hi,

I am currently using the FeatureStatPlot function from the SCP package. I would like to know how to customize the order of groups within this function. I have tried using the method to change the order in Seurat, but it doesn't seem to work.

bellow is my code:

[email protected] <- [email protected]$celltype 
levels(adata)

tmp <- adata
My_levels <- c('2C','Morula','ICM','TE','Epi','PrE','VE')
Idents(tmp) <- factor(Idents(tmp), levels= My_levels)

levels(Idents(tmp))
@hermespara
Copy link

You need to change the order of factors directly in the metadata column.

[email protected]$celltype <- factor([email protected]$celltype, levels = c('2C','Morula','ICM','TE','Epi','PrE','VE'))
FeatureStatPlot(pancreas_sub, stat.by = c("Your Variable to plot"), group.by = "celltype")

@jphe
Copy link
Author

jphe commented Jun 19, 2024

Thanks a lot for your reply, I have tried the code above it works well.

However, it seems not compatible with the bg.by option, it reports an error as bellow.

if omit the bg.by='celltyp' option, the function works without any issues.

FeatureStatPlot(
  srt = tmp, group.by = "celltype", bg.by='celltype',
  stat.by =c("Zscan4c"), add_box = TRUE,
)

Error in colnames(df_table)[apply(df_table, 1, function(x) which(x > 0))]: 类别为'list'的下标不对
Traceback:

1. FeatureStatPlot(srt = tmp, group.by = "celltype", bg.by = "celltype", 
 .     stat.by = c("MERVL-int"), add_box = TRUE, )
2. ExpressionStatPlot(exp.data = exp.data, meta.data = meta.data, 
 .     stat.by = stat.by, group.by = group.by, split.by = split.by, 
 .     bg.by = bg.by, plot.by = "group", fill.by = fill.by, cells = cells, 
 .     keep_empty = keep_empty, individual = individual, plot_type = plot_type, 
 .     palette = palette, palcolor = palcolor, alpha = alpha, bg_palette = bg_palette, 
 .     bg_palcolor = bg_palcolor, bg_alpha = bg_alpha, add_box = add_box, 
 .     box_color = box_color, box_width = box_width, box_ptsize = box_ptsize, 
 .     add_point = add_point, pt.color = pt.color, pt.size = pt.size, 
 .     pt.alpha = pt.alpha, jitter.width = jitter.width, jitter.height = jitter.height, 
 .     add_trend = add_trend, trend_color = trend_color, trend_linewidth = trend_linewidth, 
 .     trend_ptsize = trend_ptsize, add_stat = add_stat, stat_color = stat_color, 
 .     stat_size = stat_size, stat_stroke = stat_stroke, stat_shape = stat_shape, 
 .     add_line = add_line, line_color = line_color, line_size = line_size, 
 .     line_type = line_type, cells.highlight = cells.highlight, 
 .     cols.highlight = cols.highlight, sizes.highlight = sizes.highlight, 
 .     alpha.highlight = alpha.highlight, calculate_coexp = calculate_coexp, 
 .     same.y.lims = same.y.lims, y.min = y.min, y.max = y.max, 
 .     y.trans = y.trans, y.nbreaks = y.nbreaks, sort = sort, stack = stack, 
 .     flip = flip, comparisons = comparisons, ref_group = ref_group, 
 .     pairwise_method = pairwise_method, multiplegroup_comparisons = multiplegroup_comparisons, 
 .     multiple_method = multiple_method, sig_label = sig_label, 
 .     sig_labelsize = sig_labelsize, aspect.ratio = aspect.ratio, 
 .     title = title, subtitle = subtitle, xlab = xlab, ylab = ylab, 
 .     legend.position = legend.position, legend.direction = legend.direction, 
 .     theme_use = theme_use, theme_args = theme_args, force = force, 
 .     seed = seed)
3. setNames(colnames(df_table)[apply(df_table, 1, function(x) which(x > 
 .     0))], rownames(df_table))

@hermespara
Copy link

I'm sorry. I cannot reproduce this error.
Maybe you can try to reproduce the df_table and check if there's something wrong.
df_table <- table([email protected][["celltype"]], [email protected][["celltype"]])
setNames(colnames(df_table)[apply(df_table, 1, function(x) which(x > 0))], rownames(df_table))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants