Skip to content

Commit b557876

Browse files
committed
m
1 parent 2aa779f commit b557876

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

R/plot_add.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,22 @@ add_box <- function(...) {
7777
}
7878
}
7979

80+
## adapted from graphics::grid
81+
g.grid.at <- function (side, n, axp, usr2) {
82+
if (is.null(n)) {
83+
stopifnot(is.numeric(ax <- axp), length(ax) == 3L)
84+
graphics::axTicks(side, axp=ax, usr=usr2, log=FALSE)
85+
} else if (!is.na(n) && (n <- as.integer(n)) >= 1L) {
86+
at <- seq.int(usr2[1L], usr2[2L], length.out = n + 1L)
87+
at[-c(1L, n + 1L)]
88+
}
89+
}
8090

8191
add_grid <- function(nx=NULL, ny=nx, col="lightgray", lty="dotted", lwd=1) {
8292

8393
p <- unlist(get.clip())
8494
reset.clip()
8595

86-
## adapted from graphics::grid
87-
g.grid.at <- function (side, n, axp, usr2) {
88-
if (is.null(n)) {
89-
stopifnot(is.numeric(ax <- axp), length(ax) == 3L)
90-
graphics::axTicks(side, axp=ax, usr=usr2, log=FALSE)
91-
} else if (!is.na(n) && (n <- as.integer(n)) >= 1L) {
92-
at <- seq.int(usr2[1L], usr2[2L], length.out = n + 1L)
93-
at[-c(1L, n + 1L)]
94-
}
95-
}
96-
9796
atx <- if (is.null(nx) || (!is.na(nx) && nx >= 1))
9897
g.grid.at(1L, nx, axp=graphics::par("xaxp"), usr2 = p[1:2])
9998
aty <- if (is.null(ny) || (!is.na(ny) && ny >= 1))

R/plot_axes.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
zebra <- function(cex=1, x=NULL, y=NULL, width=NULL, col=c("black", "white")) {
33

4-
clip <- terra:::get.clip()
4+
clip <- get.clip()
55
axs <- unlist(clip)[1:4]
66
if (is.null(width)) {
77
width <- rep(min(axs[2]-axs[1], axs[4]-axs[3]) / 100, 2) * cex
@@ -14,10 +14,12 @@ zebra <- function(cex=1, x=NULL, y=NULL, width=NULL, col=c("black", "white")) {
1414
}
1515

1616
if (is.null(x)) {
17-
x = graphics:::.grid.at(1L, NULL, log=FALSE, equilogs=TRUE, axp=par("xaxp"), usr2=par("usr")[1:2])
17+
x <- g.grid.at(1L, NULL, axp=graphics::par("xaxp"), usr2=graphics::par("usr")[1:2])
18+
#x = graphics::.grid.at(1L, NULL, log=FALSE, equilogs=TRUE, axp=par("xaxp"), usr2=par("usr")[1:2])
1819
}
1920
if (is.null(y)) {
20-
y = graphics:::.grid.at(2L, NULL, log=FALSE, equilogs=TRUE, axp=par("yaxp"), usr2=par("usr")[1:2])
21+
y <- g.grid.at(2L, NULL, axp=graphics::par("yaxp"), usr2=graphics::par("usr")[1:2])
22+
#y = graphics:::.grid.at(2L, NULL, log=FALSE, equilogs=TRUE, axp=par("yaxp"), usr2=par("usr")[1:2])
2123
}
2224

2325
x <- sort(unique(c(axs[1:2], x)))
@@ -43,7 +45,7 @@ zebra <- function(cex=1, x=NULL, y=NULL, width=NULL, col=c("black", "white")) {
4345
e <- c(axs[1] + width[1], axs[2] - width[1], axs[3] + width[2], axs[4] - width[2])
4446
lines(ext(e), xpd=TRUE)
4547
lines(ext(axs), xpd=TRUE)
46-
try(terra:::set.clip(e, clip$geo))
48+
try(set.clip(e, clip$geo))
4749
}
4850

4951

R/plot_scale.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ north <- function(xy=NULL, type=1, label="N", angle=0, d, head=0.1, xpd=TRUE, ..
169169
}
170170

171171
draw_box <- function(xy, d, below, labels, box.col, cex=1, ...){
172-
h <- strheight("A", cex=cex)
173-
w <- c(strwidth(labels[1], cex=cex), strwidth(labels[length(labels)], cex=cex))
172+
h <- graphics::strheight("A", cex=cex)
173+
w <- c(graphics::strwidth(labels[1], cex=cex), graphics::strwidth(labels[length(labels)], cex=cex))
174174
box.col <- rep(box.col, length.out=2)
175175
b <- ifelse(isTRUE(nchar(below) > 1), 3.5, 1.5)
176176
e <- c(xy[1]-1.5*w[1], xy[1]+d+w[2], xy[2]-b*h, xy[2]+3*h)
@@ -191,6 +191,7 @@ sbar <- function(d, xy=NULL, type="line", divs=2, below="", lonlat=NULL, labels,
191191

192192
box=FALSE
193193
box.col=c("white", "black")
194+
box.adj=c(0,0,0,0)
194195

195196
stopifnot(type %in% c("line", "bar"))
196197
pr <- graphics::par()
@@ -248,14 +249,12 @@ box.col=c("white", "black")
248249
lines(rbind(c(xtick[i], xy[2]), c(xtick[i], xy[2]+tadd)), lwd=ceiling(lwd/2), xpd=TRUE, ...)
249250
}
250251
}
251-
tadd <- max(strheight("0", cex=1)/5, tadd)
252+
tadd <- max(graphics::strheight("0", cex=1)/5, tadd)
252253
if (length(labels) == 1) labels =c("", labels, "")
253254
add_text(xy[1]+c(0,dd/2,dd),xy[2]+tadd, labels=labels, xpd=xpd, adj=adj, halo=halo, col=col, ...)
254255

255256
} else if (type == "bar") {
256257
stopifnot(divs > 0)
257-
258-
259258
if (missing(adj)) {
260259
adj <- c(0.5, -1)
261260
}
@@ -268,6 +267,11 @@ box.col=c("white", "black")
268267
if (box) draw_box(xy, dd, below, labels, box.col, ...)
269268

270269
half <- xy[1] + dd / 2
270+
if (halo) {
271+
graphics::polygon(c(xy[1], xy[1], xy[1]+dd, xy[1]+dd),
272+
c(xy[2], xy[2]+lwd, xy[2]+lwd, xy[2]), col="white", xpd=xpd, border="white", lwd=3)
273+
}
274+
271275
graphics::polygon(c(xy[1], xy[1], half, half), c(xy[2], xy[2]+lwd, xy[2]+lwd, xy[2]), col=fill[1], xpd=xpd, border=border)
272276
graphics::polygon(c(half, half, xy[1]+dd, xy[1]+dd ), c(xy[2], xy[2]+lwd, xy[2]+lwd, xy[2]), col=fill[2], xpd=xpd, border=border)
273277

@@ -297,9 +301,9 @@ box.col=c("white", "black")
297301
if (below != "") {
298302
adj[2] <- -adj[2]
299303
if (type == "line") {
300-
xy[2] <- xy[2] - strheight("1")/1.5
304+
xy[2] <- xy[2] - graphics::strheight("1")/1.5
301305
} else {
302-
xy[2] <- xy[2] - strheight("1")/4
306+
xy[2] <- xy[2] - graphics::strheight("1")/4
303307
}
304308
add_text(xy[1]+(dd/2), xy[2], xpd=xpd, labels=below, adj=adj, halo=halo, col=col, ...)
305309
}

man/sbar.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sbar(d, xy=NULL, type="line", divs=2, below="", lonlat=NULL, labels,
2929
\item{scaleby}{numeric. If \code{labels} is not provided. The labels are divided by this number. For example, use 1000 to go from m to km}
3030
\item{halo}{logical. If \code{TRUE} the "line" type scale bar gets a white background}
3131
\item{col}{the font color for the labels}
32-
\item{fill}{the fill color for the bar}
32+
\item{fill}{the fill color(s) for the bar}
3333
\item{border}{the color of the border around the bar}
3434
\item{...}{graphical arguments to be passed to other methods }
3535
}

0 commit comments

Comments
 (0)