AustralianAntarcticDivision / SOmap

Southern Ocean round maps
https://australianantarcticdivision.github.io/SOmap/
24 stars 6 forks source link

Degrees symbol broken #108

Closed Maschette closed 5 months ago

Maschette commented 1 year ago

The degrees symbol seems to be broken in both normal and SOgg plotting options?

library(SOmap)
#> Loading required package: raster
#> Loading required package: sp
x<-c(20,160)

y<-c(-30, -60)

map<-SOgg(SOmap_auto(x,y,input_points=F, input_lines = F))

map

Created on 2023-02-02 with reprex v2.0.2

raymondben commented 1 year ago

It's working fine for me. What's your sessionInfo() - maybe different package versions somewhere? The graticule labels are rendered by graphics::text. What does

plot(0, 1, type = "n")
text(0, 1, labels = parse(text = c("100*degree*E")))

look like? If that's also broken, it's that.

Maschette commented 1 year ago

That's also broken... It seems to be a ragg/ggplot issue https://github.com/r-lib/ragg/issues/51

raymondben commented 1 year ago

Thomas seems to think it's a base R problem (not ragg), to do with the default Windows graphics device (and introduced in R 4.2.2). I am not near a Windows machine at the moment, can you test this please:

plot(0, 1, type = "n")
text(0, 1, labels = c("100\u00b0E"))

(i.e. using the Unicode degree symbol rather than relying on the "degree" being converted into whatever symbol it's being converted into. If that works, we can use it as a work-around)

Maschette commented 1 year ago

That works

raymondben commented 1 year ago

Should be fixed in the dev-0.7 branch, by https://github.com/AustralianAntarcticDivision/SOmap/commit/9246d6684362977cd51744b882aa5a7999bcf684 Needs testing on Windows

Maschette commented 1 year ago

It works for base plot but no the SOgg version.

Maschette commented 1 year ago

Tracking it back, in the ggplot version I think it is because for ggplot we have conveniently been using the degree_label crated by the graticule package, which uses the degreeLabelsEW and degreeLabelsNS functions from sp which are still using "*degree"

https://github.com/edzer/sp/blob/f8488cfbe10deb99c74b2ae2b12524f2bc01524f/R/gridlines.R#L14

raymondben commented 1 year ago

For our ggplot rendering it's happening in geom_sf, and we have no control over it. There is an existing issue: https://github.com/tidyverse/ggplot2/issues/5147 You should see the same problem with (first example from the geom_sf help):

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

(Our graticule labels, containing the unicode degree symbol, are used when we base-plot but not ggplot - for ggplot we are allowing geom_sf to do it, completely independently of the labels that we construct. It might be possible to suppress geom_sf's label handling and pass our own, but I'm not sure about that ...)

raymondben commented 1 year ago

@Maschette I've added a borderline ridiculous and certainly ill-advised workaround in https://github.com/AustralianAntarcticDivision/SOmap/commit/056a49a92335c36756aefc4985ba2e0eba5b4b20. Hopefully the underlying issue gets resolved soon, but in the meantime this might get us by. Could you test pls ...

raymondben commented 1 year ago

Confirmed that this is a known bug in R 4.2.2 (https://bugs.r-project.org/show_bug.cgi?id=18440) and has been fixed for the next R version (https://github.com/wch/r-source/commit/ffa365b1e993ec2ed79499d3188b0f6e9fc270dc). So if our dodgy patch works, we should only need to actually use it if the user is running R 4.2.2 on Windows.

Maschette commented 5 months ago

I believe this is fixed now and can be closed?