I am switching from basic R plot tools to ggplot2 and am struggling with one issue.
In basic R you can control distance to each of four axes (or the "box") by setting margins. Resulting margins are fixed and do not depend on what you plot. These allows me to produce plots for my papers with exactly same plot area sizes despite the size of tick labels and axis labels.
In ggplot, I ecnountered this (minimum working example):
library(ggplot2)
dat = data.frame(x = 1:5, y = 1e-5* (1:5) ^ 2)
p = ggplot(dat, aes(x, y)) + geom_point() + geom_line()
print(p)
print(p + scale_y_log10())
Black arrows at the left-hand side of the plots show the difference between actual margins I get. Axis label(y
) stays in place, while position of the y
-axis shifts depending on the size of tick labels (text representation). It can be further escalated by changing axis.text.y
to e.g. increase size
.
What I desire is to be able to control actual margins no matter what tick labels are drawn - in that case I can achieve same sizes of figures of different data sets.