Here is a short reprex
valN <- 2000
valCorr <- .7
matCov <- matrix(c(1, valCorr, valCorr, 1), byrow = TRUE, ncol = 2)
vecMeans <- c(0, 0)
MASS::mvrnorm(n = valN, mu = vecMeans, Sigma = matCov) %>%
as_tibble(.name_repair = "universal") %>%
rename(Pre = `...1`,
Post = `...2`) %>%
mutate(ID = row_number(),
group = ID %% 2) -> tibDat
First a simple plot: no unnecessary white space.
ggplot(data = tibDat,
aes(x = Pre, y = Post)) +
geom_point(alpha = .1) +
geom_smooth() +
xlim(c(-4, 4)) +
ylim(c(-4, 4)) +
coord_fixed()
Now facet the plot without coord_fixed()
, no unwanted white space.
ggplot(data = tibDat,
aes(x = Pre, y = Post)) +
facet_grid(cols = vars(group),
space = "free",
) +
geom_point(alpha = .1) +
geom_smooth() +
xlim(c(-4, 4)) +
ylim(c(-4, 4))
And then this which adds facetting and illustrates the additional white space appearing when I add coord_fixed()
.
ggplot(data = tibDat,
aes(x = Pre, y = Post)) +
facet_grid(cols = vars(group),
space = "free",
) +
geom_point(alpha = .1) +
geom_smooth() +
xlim(c(-4, 4)) +
ylim(c(-4, 4)) +
coord_fixed()
The issue is there exporting to html, pdf or word. Bigger reprex at https://www.psyctc.org/R/reprex_20240710.Rmd with and here in my Rblog. TIA for any suggestions.