wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
650 stars 37 forks source link

Missing text spacing #92

Closed mgei closed 1 year ago

mgei commented 1 year ago

I have issues with spacing of text. It occurs sometimes, after I've been doing other things and other plots in R before. image

library(ggplot2)
library(dplyr)
library(ggtext)

mtcars %>%
  mutate(
    transmission = ifelse(am == 1, "automatic", "manual")
  ) %>%
  ggplot(aes(hp, mpg, color = transmission)) +
  geom_point(size = 2) +
  scale_color_manual(
    values = c(automatic = "#0072B2", manual = "#D55E00"),
    guide = "none"
  ) +
  labs(
    x = "Horse power",
    y = "Miles per gallon (MPG)",
    title = "<span style = 'font-size:14pt; font-family:Helvetica;'>Transmission type impacts fuel efficiency</span><br>
MPG is higher for <span style = 'color:#0072B2;'>automatic</span>
than for <span style = 'color:#D55E00;'>manual</span> transmissions"
  ) +
  theme_bw() +
  theme(
    plot.title = element_textbox_simple(
      size = 14, lineheight = 1, padding = margin(0, 0, 5, 0)
    )
  )
> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=de_CH.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=de_CH.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] showtext_0.9-5    sysfonts_0.8.8    showtextdb_3.0    ggtext_0.1.1      MetBrewer_0.2.0   gghighlight_0.3.3 zoo_1.8-10        lubridate_1.8.0   forcats_0.5.1     stringr_1.4.0    
[11] dplyr_1.0.9       purrr_0.3.4       readr_2.1.2       tidyr_1.2.0       tibble_3.1.7      ggplot2_3.3.6     tidyverse_1.3.1  

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.2 haven_2.5.0      lattice_0.20-45  colorspace_2.0-3 vctrs_0.4.1      generics_0.1.2   utf8_1.2.2       rlang_1.0.2      gridtext_0.1.4   pillar_1.7.0     glue_1.6.2      
[12] withr_2.5.0      DBI_1.1.2        dbplyr_2.1.1     modelr_0.1.8     readxl_1.4.0     lifecycle_1.0.1  munsell_0.5.0    gtable_0.3.0     cellranger_1.1.0 rvest_1.0.2      labeling_0.4.2  
[23] tzdb_0.3.0       markdown_1.1     fansi_1.0.3      broom_0.8.0      Rcpp_1.0.8.3     scales_1.2.0     backports_1.4.1  jsonlite_1.8.0   fredr_2.1.0      farver_2.1.0     fs_1.5.2        
[34] digest_0.6.29    hms_1.1.1        stringi_1.7.6    grid_4.2.1       cli_3.3.0        tools_4.2.1      magrittr_2.0.3   crayon_1.5.1     pkgconfig_2.0.3  ellipsis_0.3.2   xml2_1.3.3      
[45] reprex_2.0.1     assertthat_0.2.1 httr_1.4.3       rstudioapi_0.13  R6_2.5.1         compiler_4.2.1  
mgei commented 1 year ago

Solution was to install the newest version of gridtext using remotes::install_github("wilkelab/gridtext").

Problem was discussed here: https://github.com/wilkelab/gridtext/issues/24

dchiu911 commented 1 year ago

Should we add a minimum version dependency gridtext (>= 0.1.5)?