Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

sf - How to fix degree symbol not showing correctly in R on Linux/Fedora 31

Any map I make with:

ggplot() + geom_sf()

produces the expected map, but does not show the degree sign correctly, as appears from the following picture.

Corner of map with wrong degree sign

The answer given in this answer on SO - degree symbol incorrect in map axis labels - does not help, and I am posting a separate question as I see a different sign.

Changing font does not help.

I've also tried installing the current version of sf (0.9) from Github in a separate project with renv, but have the same result.

I'm on Linux, Fedora 31.

To replicate:

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

ggplot() +
  geom_sf(data = nc)

2019-03-15 update

The issue is not specific to ggplot/geom_sf; as suggested in the comments, I get the same issue with plot.new(); text(0.5,0.5, bquote(120*degree*N), cex=5) additional example of wrong degree sign

Also, to clarify, I have not the issue related to Wine detailed in the help of ?X11(). If I run in my terminal, fc-match Symbol, I get:

StandardSymbolsPS.t1: "Standard Symbols PS" "Regular"

Update 2019-03-19

Confirmed on a fresh Fedora 31 and Fedora 32 beta install. Probably a Fedora issue.

I tried with different locales (including e.g. "en_US.UTF-8" or "German") and devices (e.g. cairo_pdf(), cairo_ps()) with the same result.

X11.options() shows "cairo" as type (changing it to Xlib, or dbcairo does not change the result).

Using the TestChars() function proposed by dww in the answer below shows the following: test

However, if I knit to pdf with knitr, I get most symbols, including °.

test from pdf

If I knit to html, I get the usual garbled signs.

2020-03-20 update

As suggested by @jpmam1, this seems to be related to a regression in pango, that can be temporarily fixed by downgrading pango. Dowgrading pango however, breaks other core parts of the OS, such as nautilus.

I opened a bug on Fedora: https://bugzilla.redhat.com/show_bug.cgi?id=1815128

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are two solutions for your problem using R (ver3.6.3 2020-02-29) / R Studio (ver1.2.5033) running on a Fedora 31 VirtualBox VM:

1) Insert the unicode character using custom scales to produce the correct symbols (include N/S or E/W depending on your long/lat):

#install.packages("ggplot2")
#install.packages("sf")
library("ggplot2")
library("sf")

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

ggplot() +
  geom_sf(data = nc) +
  scale_x_continuous(labels = function(x) paste0(x, 'u00B0', "W")) +
  scale_y_continuous(labels = function(x) paste0(x, 'u00B0', "N"))

2) Downgrade the pango library. In Fedora 31, pango was upgraded to 1.44, which affects bitmap fonts like the default R-Studio font due to the switch from Freetype to HarfBuzz. Downgrading the package fixes rendering of special characters system-wide. This should solve the problem in Fedora 32 as well (untested).

sudo dnf downgrade --releasever 30 pango-1.43.0-4.fc30.x86_64

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...