This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to add space in specific location in a barplot using ggplot2

Here is my sample data and code:

##  datamean_sd1<-dput(datamean_sd1[1:10,])

data<-structure(list(Organ = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 
                                         2L, 2L, 2L), .Label = c("Brain\n(GSE123968)", "Brain\n(GSE95401)", 
                                                                 "Brain\n(E-MTAB-6910)", "Lung\nA_(GSE71159)\nC_(E-MTAB-6595)\nL_(GSE139818)\nH_(GSE137501)\nC_(GSE84345)", 
                                                                 "Bone\nT_(E-MTAB-6872)\nP_(E-GEOD-61636)", "Embryo\n(E-GEOD\n-69276)", 
                                                                 "Kidney\nD_(GSE123177)\nA_(GSE135442)", "Aorta\n(E-MTAB\n-7148)", 
                                                                 "Liver\nTumor_\n(E-MTAB\n-4842)\nNASH_\n(GSE119340)", "Retina\n(GSE\n144168)", 
                                                                 "Mus\n(GSE\n14\n15\n62)", "Lym\n(GSE\n12\n93\n15)"), class = "factor"), 
                     Name = structure(1:10, .Label = c("1_Control", "1_Krit1", 
                                                       "2_Control", "2_Pdcd20", "3_Control", "3_Acute", "3_Subacute", 
                                                       "3_Chronic", "4_Control", "4_Acute", "4_Subacute", "4_Chronic", 
                                                       "5_Control", "5_Acute", "5_Subacute", "5_Chronic", "6_Control_acute", 
                                                       "6_Acute", "7_Control_subacute", "7_Subacute", "8_Control_chronic", 
                                                       "8_Chronic", "9_Control_DG", "9_DG_VEGF", "10_Control_CA1", 
                                                       "10_CA1_VEGF", "11_Control_Ectrl", "11_Control_EfCtrl", "11_E3KO", 
                                                       "12_Control", "12_Cpt1_ko", "13_Control", "13_Tsc2_ko", "14_Control", 
                                                       "14_Zmpste24_ko", "15_Control", "15_AM_ko", "16_Control", 
                                                       "16_Chemotherapy", "16_Radiation", "16_Young", "16_Aged", 
                                                       "17_EC in bone", "18_Control", "18_N1_plus_vg", "18_N1_plus_12", 
                                                       "18_N1_plus_-", "18_N1_12_-", "19_Control", "19_STZ", "20_Control", 
                                                       "20_AS_dimtdT", "21_Control", "21_AS_brighttdT", "22_Control", 
                                                       "22_Differentiated", "23_Control", "23_Liver  tumor", "24_Control", 
                                                       "24_Nash", "25_Control", "25_EAU", "26_Control", "26_ iDUX4", 
                                                       "27_Control", "27_RANKL_ko"), class = "factor"), Disease = structure(c(1L, 
                                                                                                                              1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L), .Label = c("CCM", "Seizure", 
                                                                                                                                                                              "EAE", "Stroke", "TBI", "Infla", "AOD", "CVD", "LAM", "HGPS", 
                                                                                                                                                                              "Tumor", "Pancy", "Carcino", "DK", "AS", "Home", "NASH", 
                                                                                                                                                                              "EAU", "FSHD"), class = "factor"), fill = c("#FF0000", "#FF0000", 
                                                                                                                                                                                                                          "#00FF00", "#00FF00", "#7570B3", "#7570B3", "#7570B3", "#7570B3", 
                                                                                                                                                                                                                          "#A6D854", "#A6D854"), mean = c(806.898912005764, 837.595854895274, 
                                                                                                                                                                                                                                                          898.32650562378, 2208.81852805305, 212.969188902024, 195.692360171933, 
                                                                                                                                                                                                                                                          181.622170748826, 454.592532593114, 477.034742547228, 383.52324684751
                                                                                                                                                                                                                          ), sd = c(108.62191806741, 86.1336851228738, 108.18221445462, 
                                                                                                                                                                                                                                    551.492848636393, 35.6423740115715, 28.0730270395565, 42.7691784348475, 
                                                                                                                                                                                                                                    116.005320530673, 43.8700365938649, 63.2689449323908)), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                          10L), class = "data.frame")
data

# 1
ggplot(data = data, aes(weave_factors(Name,Disease,Organ), mean,fill=fill,group=Disease))+
  geom_bar(position="dodge", stat="identity",width = 0.8,color="black") +
  geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd),position = position_dodge(0.8), width = .2) +
  theme_classic2() +
  theme(legend.position = "none") +
  theme(axis.text.x=element_text(vjust=1,size=10))+
  labs(title = "Igfbp7", x = NULL, y = "FPKM_value") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_x_discrete(guide = "axis_nested")+
  theme(plot.margin = unit(c(5, 20, 30, 7), "mm"))+
  #  rotate_x_text(angle = 45)+
  guides(x = ggh4x::guide_axis_nested(angle = -45))

Now I get this plot but I wanna draw a bigger space between different group grouping by "Disease" . enter image description here As is showed in the picture above . I don't know how to do it manually.

I need your help.

grouping r ggplot2

Soryy , I tried facet faceting function. You know there are three labels that should be add to x axis

Firs the common lable named Name.

Second the Disease grouping information.

The last one is Organ information which contains all of them above but stay below all of them.

And if I use faceting function I will lost the last label and I will find a other method to add it again.

You can combine disease and organ into one group (e.g. CCM_GSE12368) and facet over that.

I'm not able to copy your example data. Can you double check it's formatted correctly?

0 answers

No answers yet.

Log in to answer this question.