Skip to content

Commit

Permalink
Allow right and top axes to shift to nearest facet - fixes #389
Browse files Browse the repository at this point in the history
  • Loading branch information
hafen committed Aug 24, 2024
1 parent da88816 commit 779dda5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: geofacet
Title: 'ggplot2' Faceting Utilities for Geographical Data
Version: 0.2.1
Version: 0.2.2
Authors@R: c(
person("Ryan", "Hafen", email = "[email protected]", role = c("aut", "cre")),
person("Barret", "Schloerke", email = "[email protected]", role = "ctb"))
Expand Down Expand Up @@ -33,5 +33,5 @@ Suggests:
rmarkdown
URL: https://github.com/hafen/geofacet, https://hafen.github.io/geofacet/
BugReports: https://github.com/hafen/geofacet/issues
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
22 changes: 16 additions & 6 deletions R/facet_geo.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ get_geofacet_grob <- function(x) {
nr <- max(grd$row)
for (ii in seq_len(nc)) {
idx <- which(!is.na(grd$label[grd$col == ii]))
l1 <- paste0("axis-b-", ii, "-", nr)
b1 <- paste0("axis-b-", ii, "-", nr)
t1 <- paste0("axis-t-", ii, "-1")
if (length(idx) > 0) {
last <- max(idx)
l2 <- paste0("axis-b-", ii, "-", last)
g$layout[g$layout$name == l1, c("t", "b")] <-
g$layout[g$layout$name == l2, c("t", "b")]
b2 <- paste0("axis-b-", ii, "-", last)
g$layout[g$layout$name == b1, c("t", "b")] <-
g$layout[g$layout$name == b2, c("t", "b")]
first <- min(idx)
t2 <- paste0("axis-t-", ii, "-", first)
g$layout[g$layout$name == t1, c("t", "b")] <-
g$layout[g$layout$name == t2, c("t", "b")]
} else {
extra_rgx <- c(extra_rgx, l1)
extra_rgx <- c(extra_rgx, b1)
}
}
}
Expand All @@ -115,13 +120,18 @@ get_geofacet_grob <- function(x) {
for (ii in seq_len(max(grd$row))) {
idx <- which(!is.na(grd$label[grd$row == ii]))
l1 <- paste0("axis-l-", ii, "-1")
r1 <- paste0("axis-r-", ii, "-", max(grd$col))
if (length(idx) > 0) {
first <- min(idx)
l2 <- paste0("axis-l-", ii, "-", first)
g$layout[g$layout$name == l1, c("l", "r")] <-
g$layout[g$layout$name == l2, c("l", "r")]
last <- max(idx)
r2 <- paste0("axis-r-", ii, "-", last)
g$layout[g$layout$name == r1, c("l", "r")] <-
g$layout[g$layout$name == r2, c("l", "r")]
} else {
extra_rgx <- c(extra_rgx, l1)
extra_rgx <- c(extra_rgx, r1, l1)
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions man/geofacet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 779dda5

Please sign in to comment.