Although a year late, I found this to be an easy fix:
ggplot(mpg, aes(cty, hwy, color = factor(year)))+
geom_point()+
facet_grid(cyl ~ drv) +
theme(panel.margin=unit(.05, "lines"),
panel.border = element_rect(color = "black", fill = NA, size = 1),
strip.background = element_rect(color = "black", size = 1))
UPDATE 2021-06-01
As of ggplot2 3.3.3
, the property panel.margin
is deprecated, and we should use panel.spacing
instead. Therefore, the code should be:
ggplot(mpg, aes(cty, hwy, color = factor(year)))+
geom_point()+
facet_grid(cyl ~ drv) +
theme(panel.spacing = unit(.05, "lines"),
panel.border = element_rect(color = "black", fill = NA, size = 1),
strip.background = element_rect(color = "black", size = 1))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…