Closed Dazcam closed 3 years ago
Thanks for bringing this issue to our attention. As an immediate workaround I believe that using the d_cols
parameter rather than the c_cols
parameter will work for your use case. See reprex below.
@raysinensis It looks like plot_dims
is treating character and factor vectors differently when applying color palettes.
library(clustifyr)
#> Warning: package 'clustifyr' was built under R version 4.0.3
library(scales)
set.seed(42)
random_groups <- sample(as.character(1:3),
size = nrow(pbmc_meta),
replace = T)
pbmc_meta$too_many_groups <- paste0(pbmc_meta$classified, "_", random_groups)
pbmc_meta$too_many_groups_fct <- factor(pbmc_meta$too_many_groups)
# using a character vector works
plot_dims(
data = pbmc_meta, # meta.data table containing UMAP or tSNE data
feature = "too_many_groups", # name of column in meta.data to color clusters by
do_legend = TRUE # should the legend be shown?
)
# using a factor throws warning, and doesn't show colors
plot_dims(
data = pbmc_meta, # meta.data table containing UMAP or tSNE data
feature = "too_many_groups_fct", # name of column in meta.data to color clusters by
do_legend = TRUE # should the legend be shown?
)
#> Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Paired is 12
#> Returning the palette you asked for with that many colors
#> Warning: Removed 1511 rows containing missing values (geom_point).
# generate discrete palette to match # of groups
discrete_pal <- hue_pal()(length(levels(pbmc_meta$too_many_groups_fct)))
plot_dims(
data = pbmc_meta,
feature = "too_many_groups_fct",
do_legend = TRUE,
d_cols = discrete_pal
)
Created on 2021-04-14 by the reprex package (v0.3.0)
Ah yes. I was hoping it would be something trivial.
Many thanks for the quick response.
I'm having trouble with the
plot_dims()
function when trying to compare the output ofplot_best_col()
as described in the introductory vingette. My code is below, note the first line was required to circumvent an additional, unrelated error to the one I'm writing about now.The error that is thrown by
plot_dims()
:I'm assuming this is caused by the default colour palette (pretty_palette) having too few colours for my data, I have ~20 clusters in my custom reference and query datasets. I have tried to set the
c_col
parameter inplot_dims()
such that it uses over 50 colours:But that didn't work. I could recode this manually but the example in the intro vignette is nice/handy and 20 or so clusters doesn't seem like a huge amount of clusters for these functions to process. Could you suggest a workaround/solution for this?