this is my first question here, i try to describe my problem the best possible. (i am sorry, if i am not successful with that)
i want to make a barplot in ggplot while using facet_grid.
plot1<-ggplot(data2,aes(x=fc4mean,y=Fraktion,fill=methode))+
facet_grid(~Standort, scales="free_y",)+
geom_barh(stat="identity",aes(fill=methode), position=position_dodge2(),width = 0.3)+
theme_bw()+
theme(axis.text.x = element_text(hjust = 1))+
scale_fill_brewer(palette = "Greys",direction=-1)+
scale_color_brewer("Black")+
theme(legend.title=element_blank())+
ylab("fraction")+
guides(colour = guide_legend(reverse=T))+
geom_errorbar(aes(xmin=fc4mean-fc4sd, xmax=fc4mean+fc4sd),position=position_dodge2(),width=0.3)
it works, but the standard settings make the bars huge and ugly. so i decided to set bar widths to 0.3. the problem is that then the groups of bars are far away from each other. so i tried to reduce the spacing.
i tried a lot of different approaches, for example workarounds with
position=position_dodge()
or
scale_y_discrete(expand = c(0, 2))+
to remove spacing between the 2 factor ticks on the y-axis. this worked but then i have massive empty space at the top and the bottom of the panels.
i tried to condense the plot with
theme(plot.margin = unit(c(5,0,5,0), "cm"))
which did not help at all. as i am not willing to give up and merge the plot in paint, i hope somebody has a nice idea how to deal with the width of the bars, the spacing between the bars, and the spacing of the panels in facet grid.
hoping for some nice input, cheers :)
with the help of your comments, i was able to create a decent plot by using the commands
scale_y_discrete(expand=expansion(c(0,2)))
position=position_dodge()
width = ()
and by adjusting the aspect ratio of the plot windows. thank you