You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Left and right margins get ignored for some elements (including plot titles and captions), but work fine for other elements (such as strip and axis labels.
Given this plot:
library(ggplot2)
p<- ggplot(mpg, aes(cty, hwy)) +
geom_point() +
facet_wrap(vars(cyl)) +
labs(
title="City vs. Highway Mileage by Cylinders",
caption="Values are in MPG."
) +
theme(
plot.background= element_rect(color="black", linewidth=1),
axis.title.y= element_text(angle=0, vjust=0.5),
strip.text= element_text(hjust=0)
)
p
You can change the top and bottom margins for the title and caption, but the left and right margins don't budge:
For some elements, say x-axis text, the horizontal margins are ignored due to the labels being linked to a single point that varies in the x-direction. This makes sense to me.
Other elements are linked to a cell in the layout, like the titles. It makes less sense to me to ignore part of the margins there.
The default theme's margins are 0 for left/right (sub)titles and captions, so I don't see any explicit harm in enabling them, but I'd like to wait out to hear what the others think.
Uh oh!
There was an error while loading. Please reload this page.
Left and right margins get ignored for some elements (including plot titles and captions), but work fine for other elements (such as strip and axis labels.
Given this plot:
You can change the top and bottom margins for the title and caption, but the left and right margins don't budge:
But all 4 margins seem to work for axis titles and strip labels:
Created on 2023-11-22 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: