@@ -504,20 +504,34 @@ sf_rescale01_x <- function(x, range) {
504
504
# ' @param crs Use this to select a specific coordinate reference system (CRS).
505
505
# ' If not specified, will use the CRS defined in the first layer.
506
506
# ' @param datum CRS that provides datum to use when generating graticules
507
- # ' @param graticule_labeling Named list of character values specifying which
508
- # ' graticules (meridians or parallels) should be labeled on which side of the
509
- # ' plot. Meridians are indicated by `"E"` (for East) and parallels by `"N"`
510
- # ' (for North). Default is `list(top = NA, right = NA, bottom = "E",
511
- # ' left = "N")` to label parallels on the left and meridians at the bottom.
507
+ # ' @param graticule_labeling Character vector or named list of character values
508
+ # ' specifying which graticules (meridians or parallels) should be labeled on
509
+ # ' which side of the plot. Meridians are indicated by `"E"` (for East) and
510
+ # ' parallels by `"N"` (for North). Default is `"NE--"`, which specifies
511
+ # ' (counter-clockwise from the left) paralleles on the left, meridians on the bottom,
512
+ # ' and nothing on the right or top. Alternatively, this setting could have been
513
+ # ' specified with `list(left = "N", bottom = "E", right = NA, top = NA)`.
512
514
# ' @param ndiscr number of segments to use for discretising graticule lines;
513
515
# ' try increasing this when graticules look unexpected
514
516
# ' @inheritParams coord_cartesian
515
517
# ' @export
516
518
# ' @rdname ggsf
517
519
coord_sf <- function (xlim = NULL , ylim = NULL , expand = TRUE ,
518
520
crs = NULL , datum = sf :: st_crs(4326 ),
519
- graticule_labeling = list ( top = NA , right = NA , bottom = " E " , left = " N " ) ,
521
+ graticule_labeling = " NE-- " ,
520
522
ndiscr = 100 , default = FALSE ) {
523
+
524
+ # graticule labeling can be specified via string or named list
525
+ if (is.character(graticule_labeling )) {
526
+ graticule_labeling <- parse_graticule_labeling(graticule_labeling )
527
+ } else if (! is.list(graticule_labeling )) {
528
+ warning(
529
+ " Graticule labeling format not recognized. Proceeding with default settings." ,
530
+ call. = FALSE
531
+ )
532
+ graticule_labeling <- list (left = " N" , bottom = " E" )
533
+ }
534
+
521
535
ggproto(NULL , CoordSf ,
522
536
limits = list (x = xlim , y = ylim ),
523
537
datum = datum ,
@@ -528,3 +542,8 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
528
542
default = default
529
543
)
530
544
}
545
+
546
+ parse_graticule_labeling <- function (x ) {
547
+ labs = unlist(strsplit(x , " " ))
548
+ list (left = labs [1 ], bottom = labs [2 ], right = labs [3 ], top = labs [4 ])
549
+ }
0 commit comments