I'm trying to run this code: fread(joineddatapath) %>% filter(labeling == "early") %>%…
- User
I'm trying to run this code: fread(joined_data_path) %>% filter(labeling == "early") %>% filter(population == 'new') %>% filter(treatment == '4sU') %>% filter(numeric_time > 4.5) %>% distinct() %>% left_join(cell_types) %>% # group_by(numeric_time, layer) %>% # summarize(m = mean(conversions, na.rm = TRUE) * 100) %>% # pivot_wider(names_from = layer, values_from = m) ggplot(aes(layer, conversions, color = layer)) + geom_violin() + theme_classic(base_size = 15) + ylim(NA, 0.1) + facet_grid(numeric_time ~ .) + stat_summary(fun.data = function(x) { return(data.frame(y = 0.5, label = paste0("n=", length(x)))) }, geom = "text", color = 'black', position = position_dodge(width = 0.75), size = 5) + stat_summary(fun.data = data_summary, color = "darkred", linewidth = 1) + stat_summary(fun.y = median, colour = "black", geom = "label", show_guide = FALSE, size = 4, vjust = 1, aes(label = paste0(round(..y.., digits = 2)))) + stat_compare_means(comparisons = list(c('evl', 'ectoderm'), c('evl', 'endoderm'), c('andoderm', 'ectoderm')))I get this error: Warning: Computation failed in stat_signif(). Caused by error in if (scalesmap(comp[1]) == data$group[1] | manual) ...: ! missing value where TRUE/FALSE needed Warning: Removed 5 rows containing missing values or values outside the scale range (geom_text()).
Assistant
The error you're encountering is coming from the stat_compare_means() function, which internally uses stat_signif(). The issue appears to be related to how the comparisons are being mapped to your data groups. Here are the most likely causes and solutions:
- Typo in comparison groups You have 'andoderm' in your comparisons, but this should probably be 'endoderm': rstat_compare_means(comparisons = list(c('evl', 'ectoderm'), c('evl', 'endoderm'), c('endoderm', 'ectoderm'))) # Fixed typo
- Missing factor levels The comparison groups might not exist in your layer variable. Check what values are actually present: r# Add this before your ggplot to check available levels unique(your_data$layer)
- Factor ordering issues If layer is a factor, make sure the levels match exactly: r# Convert to factor with explicit levels if needed your_datalayer, levels = c("evl", "ectoderm", "endoderm"))