I use ggplot2
and knitr
to publish scatterplots with a right-hand-side legend. The legend is included in the aspect ratio and therefore breaks the "squareness" of the plots, as shown in the default themes. When the legend text becomes a bit longer than "a" and "b", the graphs become "long rectangles" instead of "squares".
I would like to keep the graphs "squared", and so would like to exclude the legend from the aspect ratio on my ggplot2
graphs. My .Rprofile
has the following information to force ggplot2
to produce low-colour graphs with bigger text and more space around axis titles:
theme_set(theme_bw(16))
theme_update(
axis.title.y = element_text(angle = 90, vjust = -.25),
axis.title.x = element_text(vjust = -1),
plot.margin = unit(c(1,1,1,1), "cm")
)
Is there anything I can add here to exclude the legend from the aspect ratio? Manipulations with coord_equal
and coord_fixed
have failed so far, as have the fig.width
and fig.height
options. Thanks for your help!
Edit: working example removed, question answered below with full example code (sorry for the delay in approving the answer).