首页 文章

改变R barplot的宽度

提问于
浏览
3

我用ggplot创建了一个条形图 . 我的数据框:

variable <- c(AFD, AFD, FC, FC, NDT, NDT)
AOI<- c(R,Z,R,Z,R,Z)
mean <- c(219,228,30,130,8381,40164)
se <- c(5,5,1,4,367,1363)

df <- data.frame(variable , AOI, mean, se )

这是我的情节代码:

ggplot(data=Summary_RegBed_ZvsR_Hyp1_lang[Summary_RegBed_ZvsR_Hyp1_lang$variable == "FC", ], aes(x=variable, y=mean, fill=AOI)) +   
scale_x_discrete(labels = "Anzahl Fixationen")+
ylab("Absolute Anzahl")+
xlab("Anzahl Fixationen")+
scale_fill_grey(start = 0.35, end= 0.8,
              name = "Area of Interest",
              breaks=c("R", "Z"),
              labels=c("Rand", "Zentrum"))+
geom_bar(stat="identity", position=position_dodge(), width = .6)+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
            width=.1,                    
            position=position_dodge(.6))+
scale_y_continuous(limit=c(0,140), breaks = c(0,25, 50, 75, 100, 125))+
theme_bw() +
theme(text=element_text(family="Times", face="bold", size=12))+
theme(axis.text.x=element_blank(),
    axis.ticks.x=element_blank()) +
geom_signif(annotation="***", y_position=140, xmin=0.85, xmax=1.15, tip_length=0.008)

这是由此产生的情节
This is the resulting plot

我的问题是:如何减少条形和y轴之间的间距以及图形的条形和右边缘?我需要在彼此旁边绘制几个地块,这只会浪费我的空间 . 我尝试使用scale_x_discrete中断或限制,但没有一个工作 . 有什么建议?提前致谢!

1 回答

  • 1

    您可以将 expand 设置为零(右侧和左侧)来实现此目的:

    p +  
        scale_x_discrete( expand = c(0, 0))
    

相关问题