Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strip text justification ignored if single facet level #163

Closed
mdeber opened this issue Apr 12, 2020 · 0 comments
Closed

strip text justification ignored if single facet level #163

mdeber opened this issue Apr 12, 2020 · 0 comments

Comments

@mdeber
Copy link

mdeber commented Apr 12, 2020

Hi,

When using facet_grid(), strip text justification is correctly applied only when there are multiple facet levels. If there's only 1 facet level, it seems to be ignored:

facet_labels <- labeller(
    gear = c("3" = "three gears",
             "4" = "three gears, plus one!",
             "5" = "five gears????")
)

make_plot <- function(df) {
    ggplot(df, aes(hp, mpg)) +
    facet_grid(rows = vars(gear), 
               labeller = facet_labels) +
    geom_point() +
    theme(strip.text.y = element_text(angle = 0, hjust = 0))
}

# 3 facet levels
p3 <- make_plot(mtcars)

# 2 facet levels
p2 <- make_plot(subset(mtcars, gear != 4))

# 1 facet level
p1 <- make_plot(subset(mtcars, gear == 3))

Multiple facet levels justify correctly:

p3 / p2

p1

Single facet level ignores hjust specification:

p3 / p1

p2

(Same if all plots have 1 facet level)

p1 / make_plot(subset(mtcars, gear == 4))

p3

─ Session info ──────────────────────────────────────────────────────────────────
 setting  value                                             
 version  R Under development (unstable) (2020-01-10 r77651)
 os       macOS Catalina 10.15.4                            
 system   x86_64, darwin15.6.0                              
 ui       RStudio                                           
 language (EN)                                              
 collate  en_US.UTF-8                                       
 ctype    en_US.UTF-8                                       
 tz       America/New_York                                  
 date     2020-04-12                                        

─ Packages ──────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                              
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 4.0.0)                      
 cli           2.0.2      2020-02-28 [1] CRAN (R 4.0.0)                      
 colorspace    1.4-1      2019-03-18 [1] CRAN (R 4.0.0)                      
 crayon        1.3.4      2017-09-16 [1] CRAN (R 4.0.0)                      
 dplyr         0.8.5      2020-03-07 [1] CRAN (R 4.0.0)                      
 fansi         0.4.1      2020-01-08 [1] CRAN (R 4.0.0)                      
 ggplot2     * 3.3.0      2020-03-05 [1] CRAN (R 4.0.0)                      
 glue          1.3.2      2020-03-12 [1] CRAN (R 4.0.0)                      
 gtable        0.3.0      2019-03-25 [1] CRAN (R 4.0.0)                      
 lifecycle     0.2.0      2020-03-06 [1] CRAN (R 4.0.0)                      
 magrittr      1.5        2014-11-22 [1] CRAN (R 4.0.0)                      
 munsell       0.5.0      2018-06-12 [1] CRAN (R 4.0.0)                      
 packrat       0.5.0      2018-11-14 [1] CRAN (R 4.0.0)                      
 patchwork   * 1.0.0.9000 2020-03-11 [1] Github (thomasp85/patchwork@012fb8b)
 pillar        1.4.3      2019-12-20 [1] CRAN (R 4.0.0)                      
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.0.0)                      
 purrr         0.3.3      2019-10-18 [1] CRAN (R 4.0.0)                      
 R6            2.4.1      2019-11-12 [1] CRAN (R 4.0.0)                      
 Rcpp          1.0.4      2020-03-17 [1] CRAN (R 4.0.0)                      
 rlang         0.4.5      2020-03-01 [1] CRAN (R 4.0.0)                      
 rstudioapi    0.11       2020-02-07 [1] CRAN (R 4.0.0)                      
 scales        1.1.0      2019-11-18 [1] CRAN (R 4.0.0)                      
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 4.0.0)                      
 tibble        2.1.3      2019-06-06 [1] CRAN (R 4.0.0)                      
 tidyselect    1.0.0      2020-01-27 [1] CRAN (R 4.0.0)                      
 withr         2.1.2      2018-03-15 [1] CRAN (R 4.0.0)                      

[1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant