Remove space between bars ggplot2

前端 未结 2 1457
天涯浪人
天涯浪人 2020-12-02 00:19

This is my code

    ggplot(df, aes(x=timepoint, y=mean, fill=group)) +
            geom_bar(position=position_dodge(.3), colour=\"black\", stat=\"identity\",         


        
相关标签:
2条回答
  • 2020-12-02 00:40

    Just adjust the widths:

    ggplot(df, aes(x=timepoint, y=mean, fill=group)) +
      geom_bar(position=position_dodge(0.9), colour="black", stat="identity", width=0.9, , binwidth=0) +
      geom_errorbar(position=position_dodge(0.9), width=0.85, aes(ymin=mean, ymax=mean+sem)) +
      theme_bw() 
    

    enter image description here

    0 讨论(0)
  • 2020-12-02 00:40

    Something like this?

    df <- structure(list(group = structure(c(2L, 1L, 4L, 3L), .Label = c("a1.c.ffa.mean Control", 
    "a1.d.ffa.mean Dysglyc", "b1.c.ffa.mean Control", "b1.d.ffa.mean Dysglyc"
    ), class = "factor"), timepoint = structure(c(1L, 1L, NA, NA), .Label = c("Baseline", 
    "12W"), class = "factor"), mean = c(1.913509, 2.181959, 2.742249, 
    1.50846), sem = c(0.10663114, 0.08360294, 0.07890374, 0.08348542
    ), p.value = c(0.597738161, 1, 0.007885464, 1), p.value.t = c(0.04408, 
    1, 0.2455049, 1)), .Names = c("group", "timepoint", "mean", "sem", 
    "p.value", "p.value.t"), row.names = c(NA, -4L), class = "data.frame")
    

    reorder factor levels with

    df$timepoint <- factor(df$timepoint, 
                           levels= c('Baseline', '12W'))
    

    plot it

    ggplot(df, aes(x=factor(timepoint), y=mean, fill=group)) +
      geom_bar(position=position_dodge(.3), colour="black",
               stat="identity", width=0.3, , binwidth=0) +
      geom_errorbar(position=position_dodge(.3), width=.25,
                    aes(ymin=mean, ymax=mean+sem)) +
      scale_fill_manual(values=c("#FFFFFF", "#000000","#FFFFFF", "#000000"),
                        guide=FALSE) +
      theme_bw() +
      labs(list(x="", y='skeletal muscle FFA g/100g')) +
      # xlim("Baseline", "12w") +
      scale_x_discrete(expand = c(0,0)) + 
      scale_y_continuous(expand = c(0,0) ) + 
      theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
            panel.grid.minor = element_blank(),
            axis.line = element_line(colour = "black"))
    

    geom_bar

    Which is pretty close to your example...

    0 讨论(0)
提交回复
热议问题