add space between vioin plots and adjust statistics on plots in ggplot2 using scale_x_manual from ggh4x

47 Views Asked by At

I tried to add space between my violins with scale_x_manual function and it worked perfectly but the problem is the statistics position above the plots did not move and they are not positioned in the right place !How can I fix it?

# violin plot with noise
if(i != gene[length(gene)]){
  if (any(i == gene[seq(1, length(gene),by=7)])){
  plot_list_vln_df[[i]] <- vln_df[[i]] %>%
ggplot(mapping=aes(x=Subset, y=Expression)) + geom_violin(mapping=aes(x=Subset, y=Expression, fill= Subset), scale = "width", width= 0.8)+ scale_x_manual(as.double(c(1:3, 5:7 , 9:11, 13:16))) +scale_fill_manual(values = alpha((mycolors),0.9))+ geom_boxplot(outlier.size = 0.01, width=0.3, size=0.5, alpha=0.4) + 
    theme_bw()+
    xlab("") +
  ggtitle(label=i) +
  stat_pvalue_manual(pwc[[i]],  hide.ns = F, y.position = y.position, label = "FDR.signif", size = p.val.size, tip.length = 0) +
  labs(subtitle = get_test_label(vln_df[[i]] %>% kruskal_test(Expression ~ Subset) %>% mutate(KW_FDR = p.adjust (p, method='BH')) %>% add_significance(p.col = "KW_FDR"), p.col = "KW_FDR.signif", detailed=F, description = "KW (FDR)"))+ylim +
  theme(panel.grid = element_blank(),axis.title.y = element_text(size = 12), axis.text.y = element_text(size=12), axis.text.x = element_blank(), axis.ticks.x = element_blank(), plot.title = element_text(hjust = 0.5, size=plot.title.size, face = "bold"), plot.subtitle = element_text(size = 9))+ylab("Expression")+ theme(legend.position = "none" , aspect.ratio = 1)
} 

enter image description here

0

There are 0 best solutions below