I'm preparing a figure for a publication. I'm omitting the x label by setting xlab("")
, however ggplot2 produces a whitespace instead of completely removing the label. How can I get rid of the whitespace (marked by red rectangle in the plot below)?
The full code:
ggplot(data, aes(x=Celltype, y=Mean, fill=factor(Dose), label=p.stars)) +
geom_bar(stat = "identity", position = position_dodge(width=0.9), aes(group=Dose)) +
geom_errorbar(aes(ymin = Mean - SEM, ymax = Mean + SEM), stat = "identity", position = position_dodge(width=0.9), width=0.25) +
geom_text(aes(y = Mean + SEM), size = 5, position = position_dodge(width=0.9), hjust = .5, vjust = -1) +
xlab("") +
ylab("Concentration") +
scale_fill_grey(name = "Dose") +
theme_bw()
Use
theme()
to remove space allocated for the x axis title. When you setxlab("")
there is still space made for this title.Try this function:
You can also crop the white space in the resulting pdf file once created. In Unix, the system command is:
pdfcrop does work on Mac provided the standard LaTeX distribution (Mactex or texlive) is installed. Of course, this command can be executed in R as follows:
Have you tried
plot.margin
?