Skip to content

No error reported but not displayed when using crs and default_crs parameter in coord_sf #6382

Closed
@Breeze-Hu

Description

@Breeze-Hu

Hi, I'm using ggplot to process some geospatial data and I'm finding that setting crs and default_crs doesn't produce the expected results and no errors are reported.
I'm not sure if it's because I don't fully understand these two parameters or if it's something else.

  • crs is supposed to determine the reference system for the final plot;
  • default_crs is used to specify the original reference system for the data.

In the example below, the raw data is in the epsg:4326 coordinate system, and I'm trying to show it using a different projected coordinate system, but the plotting results are blank.

I provided data that could be reproduced: example data

library(ggplot2)
library(sf)

data <- read.csv('./example.csv', row.names = 1)

targetcrs <- paste(
  "+proj=lcc", 
  "+lat_1=25", 
  "+lat_2=47", 
  "+lon_0=105", 
  "+datum=WGS84", 
  "+units=m", 
  sep = " "
)

ggplot(data = data, aes(x = x, y = y))+
  geom_raster(aes(fill = value))+
  facet_wrap(~class)+
  coord_sf(
    crs = st_crs('epsg:32649'), # or crs = targetcrs,
    default_crs = st_crs('epsg:4326'))
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    coord 🗺️messagesrequests for improvements to error, warning, or feedback messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions