I found an alternative solution specifically for shapefiles:
### shapefile library(sf) # extract the bounding box of the shapefile bbox <- st_bbox(map) # calculate the aspect ratio aspect_ratio <- (bbox$ymax - bbox$ymin) / (bbox$xmax - bbox$xmin)