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

sf + ggplot + ragg doesn't print degree symbol #51

Closed
mhpob opened this issue Aug 31, 2020 · 26 comments
Closed

sf + ggplot + ragg doesn't print degree symbol #51

mhpob opened this issue Aug 31, 2020 · 26 comments

Comments

@mhpob
Copy link

mhpob commented Aug 31, 2020

library(sf)

nc <- sf::st_read(system.file("shape/nc.shp", package="sf"))


library(ggplot2)
map <- ggplot() +
    geom_sf(data = nc)


ragg::agg_png(width = 900, height = 450)
map
invisible(dev.off())

Rplot001

png(width = 900, height = 450)
map
invisible(dev.off())

Rplot001

@thomasp85
Copy link
Member

I cannot reproduce this. What system are you on? And does the issue persist with the development version?

@mhpob
Copy link
Author

mhpob commented Oct 1, 2020

Using Windows 10 -- just re-installed the development version of ragg and the problem persists. Here's my sessionInfo:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] ragg_0.3.1.9000 ggplot2_3.3.2 sf_0.9-6

loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 rstudioapi_0.11 magrittr_1.5 units_0.6-7 munsell_0.5.0 tidyselect_1.1.0 colorspace_1.4-1 R6_2.4.1
[9] rlang_0.4.7 dplyr_1.0.2 tools_4.0.2 grid_4.0.2 gtable_0.3.0 KernSmooth_2.23-17 e1071_1.7-3 DBI_1.1.0
[17] withr_2.3.0 systemfonts_0.3.2 ellipsis_0.3.1 class_7.3-17 tibble_3.0.3 lifecycle_0.2.0 crayon_1.3.4 textshaping_0.1.1
[25] farver_2.0.3 purrr_0.3.4 vctrs_0.3.4 glue_1.4.2 compiler_4.0.2 pillar_1.4.6 scales_1.1.1 generics_0.0.2

@thomasp85
Copy link
Member

Thanks - I'll try to check this out on windows.

@thomasp85
Copy link
Member

I can reproduce on Windows

@thomasp85
Copy link
Member

OK, so apparently the symbol font does not provide a Unicode character map but only understands the ancient Adobe Symbol encoding... this is fixable but I'll have to think about the path of least resistance (esp since it is a windows only problem)

@MargaretSiple-NOAA
Copy link

MargaretSiple-NOAA commented Nov 16, 2022

I have had this same issue recently, though I can't pinpoint when it started happening. When I use ggplot() + geom_sf(), degree symbols appear as little boxes, as they did in @mhpob 's example above. When I change to R 4.2.1 instead of 4.2.2, it resolves the issue. I have noooo idea what is happening.

Here is a reprex that will reproduce this same issue on my Windows 10 machine:

# Map test based on geom_sf() help file
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
  geom_sf(aes(fill = AREA))

which produces the following:
worldtest

I suspect that this is related to my windows fonts somehow, but any additional insight would be appreciated. I will struggle mightily before developing a hacky workaround. Thank you!

Here is my sessionInfo():

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

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

other attached packages:
[1] ggplot2_3.4.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 pillar_1.8.1 compiler_4.2.2
[4] class_7.3-20 R.methodsS3_1.8.2 R.utils_2.12.2
[7] tools_4.2.2 digest_0.6.30 lattice_0.20-45
[10] lifecycle_1.0.3 tibble_3.1.8 gtable_0.3.1
[13] R.cache_0.16.0 pkgconfig_2.0.3 rlang_1.0.6
[16] DBI_1.1.3 cli_3.4.1 rstudioapi_0.14
[19] rnaturalearthdata_0.1.0 e1071_1.7-12 withr_2.5.0
[22] dplyr_1.0.10 styler_1.8.1 generics_0.1.3
[25] vctrs_0.5.0 classInt_0.4-8 grid_4.2.2
[28] tidyselect_1.2.0 glue_1.6.2 sf_1.0-9
[31] R6_2.5.1 rnaturalearth_0.1.0 fansi_1.0.3
[34] sp_1.5-1 farver_2.1.1 purrr_0.3.5
[37] magrittr_2.0.3 units_0.8-0 scales_1.2.1
[40] rsconnect_0.8.28 assertthat_0.2.1 colorspace_2.0-3
[43] labeling_0.4.2 KernSmooth_2.23-20 utf8_1.2.2
[46] proxy_0.4-27 munsell_0.5.0 R.oo_1.25.0

@grwhumphries
Copy link

@MargaretSiple-NOAA - Ditto here - having the exact same problem with the Degree symbols not rendering.

@MargaretSiple-NOAA
Copy link

@grwhumphries Does it resolve if you use R 4.2.1 or 4.2.0 instead of 4.2.2? I am not sure if the version is the issue but that's how I was able to resolve the issue temporarily. Not ideal, but it did work!

@sraul1
Copy link

sraul1 commented Nov 30, 2022

Just updated to 4.2.2 and have this issue as well. Resolves itself in 4.2.1. here is my sessionInfo() (sorry for all the packages loaded, too deep into something to start a new session, I'll update with a cleaner environment soon)

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

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

other attached packages:
 [1] reticulate_1.26 lubridate_1.8.0 tidyterra_0.3.0 terra_1.6-17    readxl_1.4.1    broom_1.0.1    
 [7] ggpubr_0.5.0    forcats_0.5.2   stringr_1.4.1   dplyr_1.0.10    purrr_0.3.5     readr_2.1.3    
[13] tidyr_1.2.1     tibble_3.1.8    ggplot2_3.4.0   tidyverse_1.3.2

loaded via a namespace (and not attached):
 [1] httr_1.4.4          jsonlite_1.8.3      splines_4.2.2       carData_3.0-5       modelr_0.1.9       
 [6] assertthat_0.2.1    googlesheets4_1.0.1 cellranger_1.1.0    yaml_2.3.6          pillar_1.8.1       
[11] backports_1.4.1     lattice_0.20-45     glue_1.6.2          digest_0.6.30       ggsignif_0.6.4     
[16] rvest_1.0.3         colorspace_2.0-3    htmltools_0.5.3     Matrix_1.5-1        pkgconfig_2.0.3    
[21] haven_2.5.1         s2_1.1.0            scales_1.2.1        tzdb_0.3.0          proxy_0.4-27       
[26] googledrive_2.0.0   mgcv_1.8-41         generics_0.1.3      farver_2.1.1        car_3.1-1          
[31] ellipsis_0.3.2      withr_2.5.0         cli_3.4.1           magrittr_2.0.3      crayon_1.5.2       
[36] evaluate_0.18       fs_1.5.2            fansi_1.0.3         nlme_3.1-160        class_7.3-20       
[41] rstatix_0.7.1       xml2_1.3.3          data.table_1.14.4   tools_4.2.2         hms_1.1.2          
[46] gargle_1.2.1        lifecycle_1.0.3     munsell_0.5.0       reprex_2.0.2        compiler_4.2.2     
[51] e1071_1.7-12        rlang_1.0.6         units_0.8-0         classInt_0.4-8      grid_4.2.2         
[56] rstudioapi_0.14     labeling_0.4.2      rmarkdown_2.17      wk_0.7.0            gtable_0.3.1       
[61] codetools_0.2-18    abind_1.4-5         DBI_1.1.3           polynom_1.4-1       R6_2.5.1           
[66] knitr_1.40          fastmap_1.1.0       utf8_1.2.2          KernSmooth_2.23-20  stringi_1.7.8      
[71] Rcpp_1.0.9          png_0.1-7           vctrs_0.5.0         sf_1.0-8            dbplyr_2.2.1       
[76] tidyselect_1.2.0    xfun_0.34         

@icrichmond
Copy link

Also having this issue on a Windows system since updating to R 4.2.2 (resolved once I switched to R 4.2.1). Here is my sessionInfo() (sorry if its messy, this is my first time attaching sessionInfo!)

Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8   
[3] LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.utf8    

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

other attached packages:
[1] ggplot2_3.4.0   sf_1.0-9        dplyr_1.0.10    targets_0.14.0  patchwork_1.1.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9          pillar_1.8.1        compiler_4.2.2      class_7.3-20       
 [5] tools_4.2.2         qs_0.25.4           digest_0.6.30       lifecycle_1.0.3    
 [9] tibble_3.1.8        gtable_0.3.1        pkgconfig_2.0.3     rlang_1.0.6        
[13] igraph_1.3.5        DBI_1.1.3           cli_3.4.1           ggrepel_0.9.2      
[17] yaml_2.3.6          xfun_0.35           e1071_1.7-12        withr_2.5.0        
[21] knitr_1.41          generics_0.1.3      vctrs_0.5.1         classInt_0.4-8     
[25] grid_4.2.2          tidyselect_1.2.0    RApiSerialize_0.1.2 glue_1.6.2         
[29] data.table_1.14.6   R6_2.5.1            processx_3.8.0      fansi_1.0.3        
[33] base64url_1.4       farver_2.1.1        callr_3.7.3         magrittr_2.0.3     
[37] units_0.8-0         backports_1.4.1     scales_1.2.1        ps_1.7.2           
[41] codetools_0.2-18    colorspace_2.0-3    renv_0.16.0         KernSmooth_2.23-20 
[45] stringfish_0.15.7   utf8_1.2.2          proxy_0.4-27        RcppParallel_5.1.5 
[49] munsell_0.5.0 ```

@grwhumphries
Copy link

I switched back to 4.2.1 and the issue was resolved. Unsure what's going on there. Hopefully gets picked up

@thomasp85
Copy link
Member

Thanks for the reports everyone... I'll see if I can figure out what is going on - weird how the R version can affect this

@thomasp85 thomasp85 reopened this Dec 7, 2022
@dempsey-CMAR
Copy link

dempsey-CMAR commented Dec 21, 2022

Hi folks! I just updated to R 4.2.2 and am also having this problem.

Session Info:

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8    LC_MONETARY=English_Canada.utf8
[4] LC_NUMERIC=C                    LC_TIME=English_Canada.utf8    

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

loaded via a namespace (and not attached):
[1] compiler_4.2.2  tools_4.2.2     rstudioapi_0.14

@fpetersma
Copy link

Hi all! I had the same issue in R 4.2.2, and it got resolved when I switched back to R 4.2.1.

@thomasp85
Copy link
Member

I'm looking into it... will hopefully have a fix soon

@thomasp85
Copy link
Member

Hmm... I have now tried to reproduce this on a Widows machine. I am completely unable to reproduce this issue in ragg. However, I do get the reported behaviour with the default windows device so I suspect that this is the device you are all using.

To make sure, can I get any of the above posters to run this piece of code and report if they indeed experience the issue:

library(grid)
ragg::agg_png("unicode_test.png")
grid.newpage()
grid.text(expression(90*degree))
dev.off()

@MargaretSiple-NOAA
Copy link

MargaretSiple-NOAA commented Jan 10, 2023

Hi @thomasp85 -- I ran the code above (now using R 4.2.2) and the piece of code returned this. It seems like the issue doesn't occur with the code you gave, but I didn't know I had changed the device I was using! Not sure what else it could be.

When I run the code I pasted in my example above, I still get the sad squares-instead-of-degrees issue. I'm on a Windows machine too. I hope this gets us one step closer to solving the mystery...

Here's the output from your code scrap:
unicode_test

@thomasp85
Copy link
Member

Thanks for responding so quickly @MargaretSiple-NOAA — can you be more specific about how you generate the plot where you see the issue? Do you open a device with ragg::agg_png() and plot it? Do you see it in the plot pane in RStudio or in the graphics window in the R gui.

The output of my provided code heavily suggests you are not using ragg in any way

@dempsey-CMAR
Copy link

dempsey-CMAR commented Jan 11, 2023

Thanks for looking into this @thomasp85.

I can see the degree symbol when I run your code.

I don't think I am using ragg to make my maps (unless it is under the hood somewhere).

Based on your comment above, I realized that the issue depends on how I am viewing the plot.

Here is a quick reprex:

library(rnaturalearth)
library(ggplot2)

can <- ne_countries(country = "canada", returnclass = "sf")

ggplot() + geom_sf(data = can)

When I run the above code, this is what I see in the RStudio plot pane and in word and html documents generated from RMarkdown:

image

When I save the map as a png or jpg with ggsave OR render a pdf document with RMarkdown, the degree symbols show up.

image

This is my session info:

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8   
[3] LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.utf8    

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

other attached packages:
[1] sf_1.0-9            rnaturalearth_0.1.0 ggplot2_3.4.0      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9         pillar_1.8.1       compiler_4.2.2     class_7.3-20      
 [5] tools_4.2.2        lattice_0.20-45    lifecycle_1.0.3    tibble_3.1.8      
 [9] gtable_0.3.1       pkgconfig_2.0.3    rlang_1.0.6        DBI_1.1.3         
[13] cli_3.4.1          rstudioapi_0.14    e1071_1.7-12       withr_2.5.0       
[17] dplyr_1.0.10       generics_0.1.3     vctrs_0.5.1        classInt_0.4-8    
[21] grid_4.2.2         tidyselect_1.2.0   glue_1.6.2         R6_2.5.1          
[25] fansi_1.0.3        sp_1.5-1           farver_2.1.1       magrittr_2.0.3    
[29] scales_1.2.1       units_0.8-1        assertthat_0.2.1   colorspace_2.0-3  
[33] labeling_0.4.2     utf8_1.2.2         KernSmooth_2.23-20 proxy_0.4-27      
[37] munsell_0.5.0   

@thomasp85
Copy link
Member

I'm pretty sure my ideas are right - all of your issues are related to the default windows device and not anything in ragg/ggplot2/sf

In general, the default windows graphics device is horrible and you should all avoid using it :-)

Going to close this. Please open another issue if an example that clearly shows an issue in ragg is observed

@dempsey-CMAR
Copy link

Good to know!
Any other advice on how to fix the issue? It didn't happen until I started using R 4.2.2, so maybe I just need to use an earlier version.
I use RMarkdown to generate reports with maps in Word for work, so would be nice to know how to fix!

@thomasp85
Copy link
Member

in the RMarkdown file you have to specify a different graphics device than the default, using the dev option in the code chunk. See https://ragg.r-lib.org/#use-ragg-with-knitr for how to set it to using ragg

@dempsey-CMAR
Copy link

dempsey-CMAR commented Jan 11, 2023

I will check that out - thanks again!

Edit - adding knitr::opts_chunk$set(dev = "ragg_png") to my RMarkdown document fixed the issue for me.

@MargaretSiple-NOAA
Copy link

@thomasp85 Thanks for that; I didn't realize that the default windows device was bad! I am grateful for this education. I changed my graphics device backend to AGG and also set it in my knitr options and all is well.

@phineas-pta
Copy link

anyone have a workaround in an interactive context? (meaning no ggsave, nor r markdown)

@thomasp85
Copy link
Member

This is not an issue with ragg but a problem with the default png device shipped with R on windows. If you use RStudio you can set change the device used in the plot pane as per the instructions in the ragg read me

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

9 participants