Resize R barplot width

I have created barplot using ggplot. My dataframe:

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 )

      

This is my code for the plot:

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 result of the graph This is the resulting plot

My question is, how can I reduce the space between the bars and y-axis and also the bars and the right edge of the chart? I need to build multiple plots next to each other and it just wastes my space. I tried using scale_x_discrete with breaks or constraints, but none of them worked. Any suggestions? Thanks in advance!

+3


source to share


1 answer


You can set expand

to zero (right and left) to achieve this:



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

      

+1


source







All Articles