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 :)
expand=
call. You should adjust toscale_y_discrete(expand=expansion(c(0,2)))
and you'll see the expansion take effect. Play around with that. I think what you're looking for is taking the original widths (where your bars are close together for "fraction") and then ADDING to the y axis via expansion on both sides. It will create whitespace above and below the bars (so it's not flat and long), but keep the bars together. Try fiddling in that way and then playing with your aspect window. – chemdork123