Skip to content

Commit b6d4540

Browse files
committed
m
1 parent a04d2a5 commit b6d4540

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

R/plot_axes.R

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

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

44
clip <- terra:::get.clip()
55
axs <- unlist(clip)[1:4]
@@ -28,13 +28,14 @@ zebra <- function(cex=1, x=NULL, y=NULL, width=NULL) {
2828
v1 <- vect(lapply(1:(length(y)-1), function(i) {
2929
as.polygons(ext(axs[1], axs[1]+width[1], y[i], y[i+1]))
3030
}))
31-
v1$col <- rep(c("black", "white"), length.out=nrow(v1))
31+
v1$col <- rep(col, length.out=nrow(v1))
3232
v2 <- shift(v1, axs[2]-axs[1]-width[1], 0)
3333

3434
h1 <- vect(lapply(1:(length(x)-1), function(i) {
3535
as.polygons(ext(x[i], x[i+1], axs[3], axs[3]+width[2]))
3636
}))
37-
h1$col <- rep(c("black", "white"), length.out=nrow(v1))
37+
38+
h1$col <- rep(col, length.out=nrow(v1))
3839
h2 <- shift(h1, 0, axs[4]-axs[3]-width[2])
3940

4041
z <- rbind(v1, v2, h1, h2)
@@ -174,7 +175,7 @@ retro_labels <- function(x, lat=TRUE) {
174175
y$line <- NA
175176
y$outer <- FALSE
176177
y$line.lab <- NULL
177-
if (is.null(y$col)) y$col <- "black"
178+
if (is.null(y$col)) y$col <- "gray"
178179
if (x$clip) {
179180
lnpts <- crds(as.points(ext(x$lim)))
180181
lnpts <- rbind(lnpts[4,], lnpts)
@@ -193,7 +194,9 @@ retro_labels <- function(x, lat=TRUE) {
193194
axt <- graphics::axTicks(s)
194195
y$at <- axt[axt >= usr[1] & axt <= usr[2]]
195196
} else {
196-
y$at <- xat[xat >= usr[1] & xat <= usr[2]]
197+
i <- (!is.na(xat)) & (xat >= usr[1]) & (xat <= usr[2])
198+
y$at <- xat[i]
199+
xlab <- xlab[i]
197200
}
198201
if (is.null(xlab)) {
199202
y$labels <- if (retro) retro_labels(y$at, lat=FALSE) else y$at
@@ -217,7 +220,9 @@ retro_labels <- function(x, lat=TRUE) {
217220
axt <- graphics::axTicks(s)
218221
y$at <- axt[axt >= usr[3] & axt <= usr[4]]
219222
} else {
220-
y$at <- yat[yat >= usr[3] & yat <= usr[4]]
223+
i <- (!is.na(yat)) & (yat >= usr[3]) & (yat <= usr[4])
224+
y$at <- yat[i]
225+
ylab <- ylab[i]
221226
}
222227
if (is.null(ylab)) {
223228
y$labels <- if (retro) retro_labels(y$at, lat=TRUE) else y$at

R/plot_raster.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@
429429

430430
if (x$zebra) {
431431
try(set.clip(x$lim, x$lonlat))
432-
zebra(width=width, x=x$axs$xat, y=x$axs$yat)
432+
zebra(width=width, x=x$axs$xat, y=x$axs$yat, col=x$zebra.col)
433433
x$lim[1:2] <- x$lim[1:2] + c(width[1], -width[1])
434434
x$lim[3:4] <- x$lim[3:4] + c(width[2], -width[2])
435435
}
@@ -463,7 +463,8 @@
463463
xlab="", ylab="", cex.lab=0.8, line.lab=1.5, asp=NULL, yaxs="i", xaxs="i",
464464
main="", cex.main=1.2, line.main=0.5, font.main=graphics::par()$font.main, col.main = graphics::par()$col.main, loc.main=NULL,
465465
sub = "", font.sub=1, cex.sub=0.8*cex.main, line.sub =1.75, col.sub=col.main, loc.sub=NULL,
466-
halo=FALSE, hc="white", hw=0.1, axes=TRUE, box=TRUE, zebra=FALSE, zebra.cex=1, maxcell=500000, buffer=FALSE, clip=TRUE,
466+
halo=FALSE, hc="white", hw=0.1, axes=TRUE, box=TRUE, zebra=FALSE, zebra.cex=1, zebra.col=c("black", "white"),
467+
maxcell=500000, buffer=FALSE, clip=TRUE,
467468
# for rgb
468469
stretch=NULL, scale=NULL, bgalpha=NULL, zlim=NULL, zcol=NULL, overview=NULL,
469470
#catch and kill
@@ -633,6 +634,7 @@
633634
out$box <- isTRUE(box)
634635
out$zebra <- isTRUE(zebra)
635636
out$zebra.cex <- zebra.cex
637+
out$zebra.col <- zebra.col
636638

637639
# if (!is.null(out$leg$loc)) {
638640
# out$leg$x <- out$leg$loc

R/plot_vector.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ setMethod("dots", signature(x="SpatVector"),
420420
}
421421

422422
if (out$zebra) {
423-
zebra(width=width, x=out$axs$xat, y=out$axs$yat)
423+
zebra(width=width, x=out$axs$xat, y=out$axs$yat, col=out$zebra.col)
424424
out$lim[1:2] <- out$lim[1:2] + c(width[1], -width[1])
425425
out$lim[3:4] <- out$lim[3:4] + c(width[2], -width[2])
426426
}
@@ -451,7 +451,8 @@ setMethod("dots", signature(x="SpatVector"),
451451
.prep.vect.data <- function(x, y, type=NULL, cols=NULL, mar=NULL, legend=TRUE,
452452
legend.only=FALSE, levels=NULL, add=FALSE, range=NULL, fill_range=FALSE, breaks=NULL, breakby="eqint",
453453
xlim=NULL, ylim=NULL, colNA=NA, alpha=NULL, axes=TRUE, buffer=TRUE, background=NULL,
454-
pax=list(), plg=list(), ext=NULL, grid=FALSE, zebra=FALSE, zebra.cex=1, las=0, sort=TRUE, reverse=FALSE, values=NULL,
454+
pax=list(), plg=list(), ext=NULL, grid=FALSE, zebra=FALSE, zebra.cex=1, zebra.col=c("black", "white"),
455+
las=0, sort=TRUE, reverse=FALSE, values=NULL,
455456
box=TRUE, xlab="", ylab="", cex.lab=0.8, line.lab=1.5, yaxs="i", xaxs="i",
456457
main="", cex.main=1.2, line.main=0.5, font.main=graphics::par()$font.main, col.main = graphics::par()$col.main, loc.main=NULL,
457458
sub = "", font.sub=1, cex.sub=0.8*cex.main, line.sub =1.75, col.sub=col.main, loc.sub=NULL,
@@ -546,6 +547,7 @@ setMethod("dots", signature(x="SpatVector"),
546547
out$box <- isTRUE(box)
547548
out$zebra <- isTRUE(zebra)
548549
out$zebra.cex <- zebra.cex
550+
out$zebra.col <- zebra.col
549551

550552
out$add <- isTRUE(add)
551553
out$axes <- isTRUE(axes)

man/plot.Rd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ There is a separate help file for plotting a \code{\link[=plot,SpatGraticule,mis
106106
\item{alpha}{Either a single numeric between 0 and 1 to set the transparency for all colors (0 is transparent, 1 is opaque) or a SpatRaster with values between 0 and 1 to set the transparency by cell. To set the transparency for a given color, set it to the colors directly}
107107
\item{sort}{logical. If \code{TRUE} legends with categorical values are sorted. If \code{x} is a \code{SpatVector} you can also supply a vector of the unique values, in the order in which you want them to appear in the legend}
108108
\item{reverse}{logical. If \code{TRUE}, the legend order is reversed}
109-
\item{grid}{logical. If \code{TRUE} grid lines are drawn. Their properties such as type and color can be set with the \code{pax} argument}
110-
\item{zebra}{logical. If \code{TRUE}, a "zebra-box" is added to the axes. The width of the zebra-box can be set with additional argument \code{zebra.cex}}
109+
\item{grid}{logical. If \code{TRUE} grid lines are drawn. Their properties such as type and color can be set with the \code{pax} argument. The grid is drawn first such that it is covered by \code{x}. See \code{\link{add_grid}} to add grid lines on top of the map}
110+
\item{zebra}{logical. If \code{TRUE}, a "zebra-box" is added to the axes. The width of the zebra-box can be set with additional argument \code{zebra.cex}. The colors can be changed with additional argument \code{zebra.col}}
111111
\item{nc}{positive integer. Optional. The number of columns to divide the plotting device in (when plotting multiple layers)}
112112
\item{nr}{positive integer. Optional. The number of rows to divide the plotting device in (when plotting multiple layers)}
113113
\item{main}{character. Main plot titles (one for each layer to be plotted). You can use arguments \code{cex.main}, \code{font.main}, \code{col.main} to change the appearance; and \code{loc.main} to change the location of the main title (either two coordinates, or a character value such as "topleft"). You can also use \code{sub=""} for a subtitle. See \code{\link{title}}}
@@ -202,7 +202,7 @@ v <- vect(f)
202202

203203
plot(v)
204204

205-
plot(v, "NAME_2", col=rainbow(12), border=c("gray", "blue"), lwd=3)
205+
plot(v, "NAME_2", col=rainbow(12), border=c("gray", "blue"), lwd=3, zebra=TRUE)
206206

207207
plot(v, 2, pax=list(side=1:2), plg=list(x=6.16, y=50.17, cex=.8), xlim=c(5.7, 6.7))
208208

src/Makevars.ucrt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ endif
1414

1515
CXX_STD = CXX
1616

17-
#all: clean winlibs
17+
all: clean winlibs
1818

19-
#winlibs:
20-
# cp -r "$(R_TOOLS_SOFT)/share/gdal" ../inst/
21-
# cp -r "$(R_TOOLS_SOFT)/share/proj" ../inst/
19+
winlibs:
20+
cp -r "$(R_TOOLS_SOFT)/share/gdal" ../inst/
21+
cp -r "$(R_TOOLS_SOFT)/share/proj" ../inst/
2222

23-
#clean:
24-
# rm -f $(SHLIB) $(OBJECTS)
23+
clean:
24+
rm -f $(SHLIB) $(OBJECTS)
2525

26-
#.PHONY: all winlibs clean
26+
.PHONY: all winlibs clean
2727

0 commit comments

Comments
 (0)