R 删除条与条之间的间距2

R 删除条与条之间的间距2,r,ggplot2,R,Ggplot2,这是我的密码 ggplot(df, aes(x=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=mea

这是我的密码

    ggplot(df, aes(x=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"), guide=FALSE) +
            theme_bw() +
            ylab(ylab) +
            xlab("") +
            # xlim("Baseline", "12w") +
            scale_x_discrete(expand = c(0,0), limits=c("Baseline","12w")) + 
            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"))
这是我的输出,我不想要,它在“基线”和“12w”之间有太多的空间:

如何消除酒吧之间的空间

多谢各位

df是这样的:

df <- structure(list(group = c("a1.d.ffa.mean Dysglyc", "a1.c.ffa.mean Control", 
"b1.d.ffa.mean Dysglyc", "b1.c.ffa.mean Control"), timepoint = c("Baseline", 
"Baseline", "12w", "12w"), 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"), class = "data.frame", row.names = c(NA, 
-4L))

df

                  group timepoint     mean        sem     p.value p.value.t
1 a1.d.ffa.mean Dysglyc  Baseline 1.913509 0.10663114 0.597738161 0.0440800
2 a1.c.ffa.mean Control  Baseline 2.181959 0.08360294 1.000000000 1.0000000
3 b1.d.ffa.mean Dysglyc       12w 2.742249 0.07890374 0.007885464 0.2455049
4 b1.c.ffa.mean Control       12w 1.508460 0.08348542 1.000000000 1.0000000
像这样的东西

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")


这与您的示例非常接近…

只需调整宽度:

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() 

缩小绘图设备的宽度。@Roland我能问一下怎么做吗?我不能简单地在R内调整大小,比率方面保持不变。你能提供所使用的数据吗?@Paulo Cardoso我已经粘贴了“df”数据。在打印之前只需调整窗口大小或在
ggsave
中指定宽度。基线应在12w之前。但在基线和12w棒之间仍然存在巨大的差距!我希望基线和12w非常接近。谢谢你的努力!请看原始帖子中的更新图片!再次感谢。好的,按照@Paulo so的建议,使用relevel()在12w之前获得基线。您知道如何从错误条参数中删除“ymin”吗?我把它设为等于他的意思,以此来“破解”它,但它很难看。我已经回答了你的问题。请不要在评论中添加其他问题。@nOOb
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"))
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()