@@ -388,7 +388,8 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
388
388
ggname(" grill" , do.call(" grobTree" , grobs ))
389
389
},
390
390
391
- render_axis_h = function (self , panel_params , theme ) {
391
+ # not used, kept around for backup
392
+ render_axis_h_alt = function (self , panel_params , theme ) {
392
393
graticule <- panel_params $ graticule
393
394
394
395
# top axis
@@ -436,7 +437,8 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
436
437
list (top = top , bottom = bottom )
437
438
},
438
439
439
- render_axis_v = function (self , panel_params , theme ) {
440
+ # not used, kept around for backup
441
+ render_axis_v_alt = function (self , panel_params , theme ) {
440
442
graticule <- panel_params $ graticule
441
443
442
444
# left axis
@@ -481,6 +483,142 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
481
483
right <- zeroGrob()
482
484
}
483
485
486
+ list (left = left , right = right )
487
+ },
488
+
489
+ render_axis_h = function (self , panel_params , theme ) {
490
+ graticule <- panel_params $ graticule
491
+
492
+ # top axis
493
+ id1 <- id2 <- integer(0 )
494
+ if (" S" %in% panel_params $ graticule_labeling ) {
495
+ id1 <- c(id1 , which(graticule $ type == " E" & graticule $ y_start > 0.999 ))
496
+ }
497
+ if (" N" %in% panel_params $ graticule_labeling ) {
498
+ id2 <- c(id2 , which(graticule $ type == " E" & graticule $ y_end > 0.999 ))
499
+ }
500
+ if (" W" %in% panel_params $ graticule_labeling ) {
501
+ id1 <- c(id1 , which(graticule $ type == " N" & graticule $ y_start > 0.999 ))
502
+ }
503
+ if (" E" %in% panel_params $ graticule_labeling ) {
504
+ id2 <- c(id2 , which(graticule $ type == " N" & graticule $ y_end > 0.999 ))
505
+ }
506
+
507
+ ticks1 <- graticule [unique(id1 ), ]
508
+ ticks2 <- graticule [unique(id2 ), ]
509
+ tick_positions <- c(ticks1 $ x_start , ticks2 $ x_end )
510
+ tick_labels <- c(ticks1 $ degree_label , ticks2 $ degree_label )
511
+
512
+ if (length(tick_positions ) > 0 ) {
513
+ top <- guide_axis(
514
+ tick_positions ,
515
+ tick_labels ,
516
+ position = " top" ,
517
+ theme = theme
518
+ )
519
+ } else {
520
+ top <- zeroGrob()
521
+ }
522
+
523
+ # bottom axis
524
+ id1 <- id2 <- integer(0 )
525
+ if (" S" %in% panel_params $ graticule_labeling ) {
526
+ id1 <- c(id1 , which(graticule $ type == " E" & graticule $ y_start < 0.001 ))
527
+ }
528
+ if (" N" %in% panel_params $ graticule_labeling ) {
529
+ id2 <- c(id2 , which(graticule $ type == " E" & graticule $ y_end < 0.001 ))
530
+ }
531
+ if (" W" %in% panel_params $ graticule_labeling ) {
532
+ id1 <- c(id1 , which(graticule $ type == " N" & graticule $ y_start < 0.001 ))
533
+ }
534
+ if (" E" %in% panel_params $ graticule_labeling ) {
535
+ id2 <- c(id2 , which(graticule $ type == " N" & graticule $ y_end < 0.001 ))
536
+ }
537
+
538
+ ticks1 <- graticule [unique(id1 ), ]
539
+ ticks2 <- graticule [unique(id2 ), ]
540
+ tick_positions <- c(ticks1 $ x_start , ticks2 $ x_end )
541
+ tick_labels <- c(ticks1 $ degree_label , ticks2 $ degree_label )
542
+
543
+ if (length(tick_positions ) > 0 ) {
544
+ bottom <- guide_axis(
545
+ tick_positions ,
546
+ tick_labels ,
547
+ position = " bottom" ,
548
+ theme = theme
549
+ )
550
+ } else {
551
+ bottom <- zeroGrob()
552
+ }
553
+
554
+ list (top = top , bottom = bottom )
555
+ },
556
+
557
+ render_axis_v = function (self , panel_params , theme ) {
558
+ graticule <- panel_params $ graticule
559
+
560
+ # right axis
561
+ id1 <- id2 <- integer(0 )
562
+ if (" N" %in% panel_params $ graticule_labeling ) {
563
+ id1 <- c(id1 , which(graticule $ type == " E" & graticule $ x_end > 0.999 ))
564
+ }
565
+ if (" S" %in% panel_params $ graticule_labeling ) {
566
+ id2 <- c(id2 , which(graticule $ type == " E" & graticule $ x_start > 0.999 ))
567
+ }
568
+ if (" E" %in% panel_params $ graticule_labeling ) {
569
+ id1 <- c(id1 , which(graticule $ type == " N" & graticule $ x_end > 0.999 ))
570
+ }
571
+ if (" W" %in% panel_params $ graticule_labeling ) {
572
+ id2 <- c(id2 , which(graticule $ type == " N" & graticule $ x_start > 0.999 ))
573
+ }
574
+
575
+ ticks1 <- graticule [unique(id1 ), ]
576
+ ticks2 <- graticule [unique(id2 ), ]
577
+ tick_positions <- c(ticks1 $ y_end , ticks2 $ y_start )
578
+ tick_labels <- c(ticks1 $ degree_label , ticks2 $ degree_label )
579
+
580
+ if (length(tick_positions ) > 0 ) {
581
+ right <- guide_axis(
582
+ tick_positions ,
583
+ tick_labels ,
584
+ position = " right" ,
585
+ theme = theme
586
+ )
587
+ } else {
588
+ right <- zeroGrob()
589
+ }
590
+
591
+ # left axis
592
+ id1 <- id2 <- integer(0 )
593
+ if (" N" %in% panel_params $ graticule_labeling ) {
594
+ id1 <- c(id1 , which(graticule $ type == " E" & graticule $ x_end < 0.001 ))
595
+ }
596
+ if (" S" %in% panel_params $ graticule_labeling ) {
597
+ id2 <- c(id2 , which(graticule $ type == " E" & graticule $ x_start < 0.001 ))
598
+ }
599
+ if (" E" %in% panel_params $ graticule_labeling ) {
600
+ id1 <- c(id1 , which(graticule $ type == " N" & graticule $ x_end < 0.001 ))
601
+ }
602
+ if (" W" %in% panel_params $ graticule_labeling ) {
603
+ id2 <- c(id2 , which(graticule $ type == " N" & graticule $ x_start < 0.001 ))
604
+ }
605
+
606
+ ticks1 <- graticule [unique(id1 ), ]
607
+ ticks2 <- graticule [unique(id2 ), ]
608
+ tick_positions <- c(ticks1 $ y_end , ticks2 $ y_start )
609
+ tick_labels <- c(ticks1 $ degree_label , ticks2 $ degree_label )
610
+
611
+ if (length(tick_positions ) > 0 ) {
612
+ left <- guide_axis(
613
+ tick_positions ,
614
+ tick_labels ,
615
+ position = " left" ,
616
+ theme = theme
617
+ )
618
+ } else {
619
+ left <- zeroGrob()
620
+ }
621
+
484
622
list (left = left , right = right )
485
623
}
486
624
@@ -518,9 +656,10 @@ sf_rescale01_x <- function(x, range) {
518
656
# ' @rdname ggsf
519
657
coord_sf <- function (xlim = NULL , ylim = NULL , expand = TRUE ,
520
658
crs = NULL , datum = sf :: st_crs(4326 ),
521
- graticule_labeling = " NE-- " ,
659
+ graticule_labeling = " NW " ,
522
660
ndiscr = 100 , default = FALSE ) {
523
661
662
+ if (FALSE ) { # commented out for now
524
663
# graticule labeling can be specified via string or named list
525
664
if (is.character(graticule_labeling )) {
526
665
graticule_labeling <- parse_graticule_labeling(graticule_labeling )
@@ -531,6 +670,8 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
531
670
)
532
671
graticule_labeling <- list (left = " N" , bottom = " E" )
533
672
}
673
+ }
674
+ graticule_labeling <- unlist(strsplit(graticule_labeling , " " ))
534
675
535
676
ggproto(NULL , CoordSf ,
536
677
limits = list (x = xlim , y = ylim ),
0 commit comments