If I create maps using geom_sf
, the axis labels have the wrong symbol for degrees. I get degree symbols that are vertically centred in the text, rather than raised like superscipts.
For example,
library(sf)
library(ggplot2)
nc = st_read(system.file("shape/nc.shp", package="sf"))
ggplot() +
geom_sf(data = nc) +
theme(axis.text = element_text(size=16))
When I see examples online, they typically look correct (e.g. image below, copied from here), so I guess it is related to something in my local setup.
I have tried changing font, using library(extrafont)
but this problem remains in every font I tried.
I don't think this is a ggplot-specific issue, as I get the same thing with any graphics that uses the degree
keyword in plotmath
. For example
par(mar=c(0,0,0,0))
plot.new()
text(0.5,0.5, bquote(120*degree*N), cex=5)
I am on Linux
(Kubuntu 19.04), R
3.5.2, ggplot2
v. 3.2.1, sf
v. 0.7-7.
Not sure what other information might be relevant, but I can update answer with anything else that is requested.
As a workaround I am creating the axis labels manually. Still looking for a better solution and explanation of the undesired behaviour.
xlabs = seq(-84,-76, 2)
ylabs = seq(34, 36.5, 0.5)
ggplot() +
geom_sf(data = nc) +
scale_x_continuous(breaks = xlabs, labels = paste0(xlabs,'°W')) +
scale_y_continuous(breaks = ylabs, labels = paste0(ylabs,'°N')) +
theme(axis.text = element_text(size=16))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With