Skip to content

Commit d6974cb

Browse files
committed
Make legend options more flexible
1 parent d5db93f commit d6974cb

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

R/add_legends.R

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
#' with [value_to_classes()]
55
#' @param LegendTitle String with title of the legend
66
#' @param LegendLocation Either "top" or "right" (outside the plot margin)
7+
#' @param ... Additional legend layout arguments
78
#'
89
#' @importFrom graphics legend
910
#' @export
1011
#'
1112
add_river_legend <- function(
12-
ext_rivers, LegendTitle = "", LegendLocation = "right"
13+
ext_rivers, LegendTitle = "", LegendLocation = "right", ...
1314
){
1415

1516
if(LegendLocation == "top"){
@@ -41,7 +42,7 @@ add_river_legend <- function(
4142

4243
nc <- length(cs)
4344
if(grepl(pattern = "^\\(", x = cs[1])){
44-
cs[1] <- paste0("< ", strsplit(x = cs[1], split = ",")[[1]][-1])
45+
cs[1] <- paste0("> ", strsplit(x = cs[1], split = ",")[[1]][-1])
4546
}
4647

4748
if(grepl(pattern = "\\)$", x = cs[nc])){
@@ -51,21 +52,12 @@ add_river_legend <- function(
5152
cs <- gsub(pattern = "\\(", replacement = "> ", x = cs)
5253
cs <- gsub(pattern = "\\,", replacement = " - ", x = cs)
5354
cs <- gsub(pattern = "\\]", replacement = "", x = cs)
55+
cs <- gsub(pattern = "^< -Inf - ", replacement = "", x = cs)
56+
cs <- gsub(pattern = " - Inf$", replacement = "", x = cs)
5457
l_content <- cs
5558
legend(x = lx, y = ly, legend = cs, col = cc, lwd = 6,
5659
bg= "white", bty = "n", title = LegendTitle,
57-
xpd = T, xjust = xadj, yjust = 0, horiz = hor)
60+
xpd = T, xjust = xadj, yjust = 0, horiz = hor, ...)
5861

5962
}
60-
ext_rivers$BVK$data$value_class
61-
62-
# ll <- length(classBreaks)
63-
# l_content <-
64-
# if(dataType == "time"){
65-
# c(paste0("<= ", classBreaks[2]), paste0("> ", classBreaks[2:(ll-1)]))
66-
# } else {
67-
# c(paste0("<= ", classBreaks[2:(ll-1)]), paste0(">", classBreaks[(ll-1)]))
68-
# }
69-
70-
7163
}

man/add_river_legend.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)