-
Notifications
You must be signed in to change notification settings - Fork 4
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
plot_heatmap Error: cannot take a sample larger than the population when 'replace = FALSE' #59
Comments
+ randomColor <- function() {
+ paste0("#", paste0(sample(c(0:9, letters[1:6]), size = 6, replace = TRUE), collapse = ""))
+ }
# make color mapping
if (is.numeric(metadata[[metadata_col]])){
#check if divergent or sequential?
row_annot <- HeatmapAnnotation(df=metadata[,metadata_col, drop=FALSE], which="row")
}else{
n_cat <- length(unique(metadata[[metadata_col]]))
qual_col_pals = brewer.pal.info[brewer.pal.info$category == 'qual',]
all_brewer_colors <- unique(unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals))))
+ if (n_cat <= length(all_brewer_colors)){
+ # get nice colors
colors <- sample(all_brewer_colors,n_cat)
+ }else{
+ # too many groups, get random colors
+ colors <- replicate(n_cat, randomColor())
+ }
names(colors) <- unique(metadata[[metadata_col]])
colors_list <- list()
colors_list[[metadata_col]] <- colors# put here the mapped colors
row_annot <- HeatmapAnnotation(df=metadata[,metadata_col, drop=FALSE], which="row", col=colors_list)
} |
Wow thats a lot of code instead of one line ^^. Sure this is all necessary? If you have tested the proposed fix feel invited to make a PR. |
It's not really that much more, highlighted it above now. Could also just remove the 'nice colors' part completely, but think it's nice that you first select for varying colors if there aren't that many |
ah okay, thought it was replacing only the one line haha |
No, I just assumed you know all your code by heart :D |
Error:
sample
call causes the issueThe text was updated successfully, but these errors were encountered: