Skip to content

the x axis ticks does not show when using sf package to plot global map #4820

Closed
@PanfengZhang

Description

@PanfengZhang

The X axis ticks does not show when using the geom_sf function of sf package to plot the global map

library(sf)
library(rnaturalearth)
library(stars)
library(ggplot2)
wld <- ne_coastline(returnclass = "sf")
diri <- "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis.derived/surface/pres.mon.ltm.nc"
da <- read_ncdf(diri, var = "pres") |> units::drop_units()
ds <- da[,,,1] |>  as.data.frame()
ds[ds$lon > 180, "lon"] <- ds[ds$lon > 180, "lon"] - 360   # 0°~360° were convert to -180~180°
sf_use_s2(FALSE)
ggplot() +
  geom_raster(data = ds, aes(x = lon, y = lat, fill = pres)) +
  geom_sf(data = wld) +
  coord_sf(expand = FALSE) +
  scale_fill_fermenter(palette = "YlOrRd", direction = -1) +
  scale_x_continuous(breaks = seq(-135, 135, 45)) +
  scale_y_continuous(breaks = seq(-45, 45, 45))

00001d

as shown in the figure, the X axis ticks does not show at the specified location.

How to solve this problem?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions