0

As seen in the image below, some characters in the axes labels are not rendered correctly. Spaces show up as boxes. This image was exported as a png. Seems to work fine when exporting to a pdf.

Running in a conda env. Perhaps something graphic related is missing?

enter image description here

library(ggplot2)

g <- ggplot(iris,aes(Sepal.Width,Petal.Width))+
  geom_point()+
  labs(x=expression(Mean~Log[2]~Fold~change),y=expression(-Log[10]~Adj~P~value))

ggsave("test.png",g)
#> Saving 7 x 5 in image

Created on 2021-08-30 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.1.0 (2021-05-18)
#>  os       Ubuntu 20.04.3 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language en_GB:en                    
#>  collate  en_GB.UTF-8                 
#>  ctype    en_GB.UTF-8                 
#>  tz       Europe/Stockholm            
#>  date     2021-08-30                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  ggplot2     * 3.3.5   2021-06-25 [1] CRAN (R 4.1.0)
#> 
#> [1] /home/user/miniconda3/envs/r-4.1/lib/R/library
mindlessgreen
  • 11,059
  • 16
  • 68
  • 113
  • This smells somehow related to https://stackoverflow.com/q/60401617/11374827 and https://stackoverflow.com/q/65898007/11374827 wherein also characters are replaced with boxes in an (ana/mini)conda environment. – teunbrand Aug 30 '21 at 14:01

1 Answers1

0

I add the same issue than you on Mac OS and managed to solve it with 2 modifications : replace ~ by %~% and add device = png in the ggsave function

g <- ggplot(iris,aes(Sepal.Width,Petal.Width))+
  geom_point()+
  labs(x=expression(Mean%~%Log[2]%~%Fold%~%change),y=expression(-Log[10]%~%Adj%~%P%~%value))

ggsave("test.png",g,device=png)

I hope this would work for you

Basti
  • 1,703
  • 3
  • 10
  • 25
  • Interesting! When I tried this, the boxes were replaced by tildas (~) rather than spaces. https://i.ibb.co/GdKNtbt/test.png – mindlessgreen Aug 30 '21 at 14:15
  • 1
    Mistake from me oops, I'm not used to `expression()` and thought you were looking to add tilde, but removing %% and keeping `device=png` do not produce the white boxes on my machine – Basti Aug 30 '21 at 14:44