patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

The x_axis text margin behavior when scale_x_discrete(position = "top")

Open abiyug opened this issue 3 years ago • 5 comments

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

patchwork_git

abiyug avatar Aug 05 '20 14:08 abiyug

Any update?

abiyug avatar Aug 07 '20 12:08 abiyug

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

thomasp85 avatar Aug 09 '20 19:08 thomasp85

I see. So is this as designed or will you look into put a fix for merging fcated cases?

abiyug avatar Aug 12 '20 15:08 abiyug

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

thomasp85 avatar Aug 12 '20 15:08 thomasp85

Don't rule it out. Thanks for responding.

abiyug avatar Aug 13 '20 14:08 abiyug