删除条ggplot2之间的空间 [英] Remove space between bars ggplot2

查看:119
本文介绍了删除条ggplot2之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

  ggplot(df,aes(x = timepoint,y = mean,fill = group)) + 
geom_bar(position = position_dodge(.3),color =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(color =black))

这是我的输出,我不想要,它在baseline和12w之间的空间太大:





如何删除栏之间的空间?



谢谢

df是这样的:

  df<  -  structure(list(group = c(a1.d.ffa.mean Dysglyc,a1.c.ffa。平均控制,
b1.d.ffa.mean Dysglyc,b1.c.ffa.mean控制),timepoint = c(Baseline,
Baseline,12w ,12w),平均值= c(1.913509,2.181959,2.72249,
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

组时间点均值sem p.value p.value.t
1 a1.d.ffa.mean Dysglyc基线1.913509 0.10663114 0.597738161 0.0440800
2 a1.c.ffa.mean控制基线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控制12w 1.508460 0.08348542 1.000000000 1.0000000






$ b $ p> ggplot(df,aes(x = timepoint,y = mean,fill = group))+
geom_bar(position = position_dodge(0.9),color =black,stat =身份,width = 0.9,binwidth = 0)+
geom_errorbar(position = position_dodge(0.9),width = 0.85,aes(ymin = mean,ymax = mean + sem))+
theme_bw )


This is my code

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

This is MY output, which I DONT want, its too much space between "baseline" and "12w":

How to remove the space between the bars?

Thank you

df is like this:

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

解决方案

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

这篇关于删除条ggplot2之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆