Stack Exchange
Blank space in ggbarplot where data is missing
Looking for a way to keep all bars the same width and leave a blank space where data is missing. Any ideas how to make that work?
p = ggbarplot(avg_neighb_ct, x = "First.Object.cellType", y = "count", 
              fill = "data", merge = TRUE, add = "mean_se", width = 0.75) + 
  theme_classic() + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 20),
        axis.text.x = element_text(size = 20, angle = 90, hjust = 1),
        axis.text.y = element_text(size = 20),
        legend.title = element_blank(),
        legend.text = element_text(size = 16)) +
  ylab("Count")
p


** EDIT **
Have added
position = position_dodge2(preserve = "single")
and now my error bars are off


Try adding position = position_dodge2(preserve = "single") to the call to ggbarplot

Thanks @Peter, have added that and it works but now my error bars are off centre :(

Have updated the answer, as it turns out position_dodge(preserve = "single") does the trick. Next time consider a reproducible question to allow realistic testing of potential solutions!

Add position = position_dodge(preserve = "single") to the call to ggbarplot
In the absence of reproducible question, adaptation of an example from the  package documentation demonstrates this:
library(ggpubr)

df3 <- ToothGrowth[!(ToothGrowth$dose == 1 & ToothGrowth$sup == "VC"), ]


ggbarplot(df3, x = "dose", y = "len", color = "supp",
          add = "mean_se", palette = c("#00AFBB", "#E7B800"),
          position = position_dodge(preserve = "single"))


Created on 2023-06-13 with reprex v2.0.2
