简体   繁体   中英

Why are the degrees not showing up in my plot?

I'm making a ggplot of a basemap with some points overlaid. I believe the default for plotting a basemap is to have the axes plot in latlong with degrees N/W (even though its projected in web mercator) but the degree symbol isn't showing up and instead is displayed as a little box?

library(sf)
library(basemaps)
library(ggplot2)
library(ggstar)

pt_df = data.frame(X = c(-10069438, -10827213),
                   Y = c(4014585, 4013104),
                   Type = c("MS", "OK"))
pt_df = st_as_sf(pt_df, coords = c("X", "Y"), crs = 3857)
bbox = st_box(pt_df)
bbox["xmin"]<- -11500000
bbox["xmax"]<- -9900000
bbox["ymin"] <- 3000000
bbox["ymax"] <- 4500000 

basemap_ggplot(bbox, map_service="osm_stamen", map_type="terrain")+
geom_star(data = pt_df, aes(x=X, y=Y, fill="red"), size=5)+
xlab("")+
ylab("")

在此处输入图像描述

I wrote out the expression to recode the x- and y- axes yet they're still showing boxes.

basemap_ggplot(bbox, map_service="osm_stamen", 
               map_type="terrain")+
geom_star(data = pt_df, aes(x=X, y=Y, fill="red"), size=5)+
xlab("")+
ylab("")+
scale_y_continuous(breaks = c(28, 30, 32, 34, 36),
                     labels = c(expression(28~degree~N),
                                expression(30~degree~N),
                                expression(32~degree~N),
                                expression(34~degree~N),
                                expression(36~degree~N)))+
  scale_x_continuous(breaks = c(-100, -95, -90, -85),
                     labels = c(expression(-100~degree~W),
                                expression(-95~degree~W),
                                expression(-90~degree~W),
                                expression(-85~degree~W)))

在此处输入图像描述

Any ideas?

Here's an example of my code but I almost think it might be some sort of setting issue and therefore isn't reproducible on someone else's computer? Any help/ideas appreciated.

We could insert unicode character: scale_y_continuous(labels = function(x) paste0(x, '°', "N"))

ggplot() +
  geom_sf(
    data = border$osm_lines,
    inherit.aes = FALSE,
    color = "black",
    size = .4,
    alpha = .8
  )+
  scale_y_continuous(labels = ~ paste0(., '\u00B0', "N"))+
  scale_x_continuous(labels = ~ paste0(., '\u00B0', "N"))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM