patchwork
patchwork copied to clipboard
The x_axis text margin behavior when scale_x_discrete(position = "top")
When patching parallel ggplot plots with the x axis text position set to the 'top', the text jumps up. This behavior doesn't happen when position is set to the "bottom".
Here is the Reprex:
library(tidyverse)
library(tidyr)
library(patchwork)
df <- mtcars %>%
select(mpg:carb) %>%
scale() %>%
as.data.frame() %>%
cbind(rown = rownames(mtcars)) %>%
pivot_longer(mpg:carb, names_to = "car_model",
values_to = "value")
gg_heat <-
ggplot(df, aes(y = rown, x = car_model, fill = value)) +
geom_tile(color = "white", size = .6) +
scale_fill_gradient(low = "white",high = "red") +
scale_x_discrete(position = "top") +
theme_bw() +
geom_text(aes(label = round(value, 2)),
colour = "black",
size = 3,
fontface = "bold")
gg_line <-
ggplot(mtcars, aes(wt, mpg)) +
geom_line() +
facet_wrap(~ am)
gg_line | gg_heat
Any update?
this is because you are merging it with a faceted plot. axes are aligned between plots which means that if a plot has facet strips in between it will move up the axes of non-faceted plots
I see. So is this as designed or will you look into put a fix for merging fcated cases?
It is unlikely to change, though I will not rule it out completely. When it comes to these edge cases patchwork will always err to the side of simplicity and consistency rather than complicating the API
Don't rule it out. Thanks for responding.