Skip to content

Commit

Permalink
tic options
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jan 9, 2024
1 parent ce62de0 commit 24b66f6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
49 changes: 45 additions & 4 deletions R/plot_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,17 @@ retro_labels <- function(x, lat=TRUE) {
}




.plot.cont.legend <- function(x, ...) {

if (!is.null(x$leg$tic)) {
accepted <- c("in", "out", "none", "through", "throughout")
tics <- accepted[pmatch(x$leg$tic[1], accepted[-5], 5)]
} else {
tics <- "throughout"
}

if (is.null(x$leg$x)) {
x$leg$x <- "right"
} else if (!(x$leg$x %in% c("left", "right", "top", "bottom"))) {
Expand Down Expand Up @@ -314,21 +323,53 @@ retro_labels <- function(x, lat=TRUE) {
graphics::rect(e$xmin, Y[-(nc + 1)], e$xmax, Y[-1], col=rev(cols), border=NA, xpd=NA)
ypos <- e$ymin + (zz - zlim[1])/(zlim[2] - zlim[1]) * e$dy
if (x$leg$x == "right") {
graphics::segments(e$xmin, ypos, e$xmax+e$dx*0.25, ypos, xpd=NA)
if (tics == "throughout") {
graphics::segments(e$xmin, ypos, e$xmax+e$dx*0.25, ypos, xpd=NA)
} else if (tics == "through") {
graphics::segments(e$xmin, ypos, e$xmax, ypos, xpd=NA)
} else if (tics == "in") {
graphics::segments(e$xmax-e$dx*0.25, ypos, e$xmax, ypos, xpd=NA)
} else if (tics == "out") {
graphics::segments(e$xmax, ypos, e$xmax+e$dx*0.25, ypos, xpd=NA)
}
text(e$xmax, ypos, zztxt, pos=4, xpd=NA, cex=cex, ...)
} else {
graphics::segments(e$xmin-e$dx*0.25, ypos, e$xmax, ypos, xpd=NA)
if (tics == "throughout") {
graphics::segments(e$xmin-e$dx*0.25, ypos, e$xmax, ypos, xpd=NA)
} else if (tics == "through") {
graphics::segments(e$xmin, ypos, e$xmax, ypos, xpd=NA)
} else if (tics == "in") {
graphics::segments(e$xmin, ypos, e$xmin+e$dx*0.25, ypos, xpd=NA)
} else if (tics == "out") {
graphics::segments(e$xmin-e$dx*0.25, ypos, e$xmin, ypos, xpd=NA)
}
text(e$xmin, ypos, zztxt, pos=2, xpd=NA, cex=cex, ...)
}
} else {
X <- seq(e$xmin, e$xmax, length.out=nc+1)
graphics::rect(X[-(nc + 1)], e$ymin, X[-1], e$ymax, col=rev(cols), border=NA, xpd=NA)
xpos <- e$xmin + (zz - zlim[1])/(zlim[2] - zlim[1]) * e$dx
if (x$leg$x == "bottom") {
graphics::segments(xpos, e$ymin-e$dy*0.25, xpos, e$ymax, xpd=NA)
if (tics == "throughout") {
graphics::segments(xpos, e$ymin-e$dy*0.25, xpos, e$ymax, xpd=NA)
} else if (tics == "through") {
graphics::segments(xpos, e$ymin, xpos, e$ymax, xpd=NA)
} else if (tics == "in") {
graphics::segments(xpos, e$ymin+e$dy*0.25, xpos, e$ymin, xpd=NA)
} else if (tics == "out") {
graphics::segments(xpos, e$ymin-e$dy*0.25, xpos, e$ymin, xpd=NA)
}
text(xpos, e$ymin, zztxt, pos=1, xpd=NA, cex=cex)
} else {
graphics::segments(xpos, e$ymin, xpos, e$ymax+e$dy*0.25, xpd=NA)
if (tics == "throughout") {
graphics::segments(xpos, e$ymin, xpos, e$ymax+e$dy*0.25, xpd=NA)
} else if (tics == "through") {
graphics::segments(xpos, e$ymin, xpos, e$ymax, xpd=NA)
} else if (tics == "in") {
graphics::segments(xpos, e$ymax, xpos, e$ymax-e$dy*0.25, xpd=NA)
} else if (tics == "out") {
graphics::segments(xpos, e$ymax, xpos, e$ymax+e$dy*0.25, xpd=NA)
}
text(xpos, e$ymax+e$dy*0.25, zztxt, pos=3, xpd=NA, cex=cex)
}
}
Expand Down
11 changes: 10 additions & 1 deletion man/plot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ There is a separate help file for plotting a \code{\link[=plot,SpatGraticule,mis
\item{background}{background color. Default is no color (white)}
\item{box}{logical. Should a box be drawn around the map?}
\item{clip}{logical. Should the axes be clipped to the extent of \code{x}?}
\item{plg}{list with parameters for drawing the legend. See the arguments for \code{\link{legend}}. Parameter \code{digits} can be used to set the number of digits to print (after the decimal point for a continuous legend). Parameter \code{size} can be used to change the height and/or width of a continuous legend. The defaults are \code{c(1,1)}, negative values for size flip the order of the legend}
\item{plg}{list with parameters for drawing the legend. For the classes and interval type legend see the arguments for \code{\link{legend}}. For example \code{x} and \code{y} can be used to place the legend. You can also use keywords such as "topleft" and "bottomright" to place the legend at these locations inside the map rectangle.

Some of these do not apply to a continuous legend, or they behave a little differently. For example, only the placement keywords "left", "right", "top", and "bottom" are recognized; and when using these keywords, the legend is placed outside of the map rectangle. Additional parameters for continuous legends include:

\itemize{
\item \code{digits} to set the number of digits to print after the decimal point. \code{size} to change the height and/or width; the defaults are \code{c(1,1)}, negative values for size flip the order of the legend.
\item \code{at} to set the location of the tic-marks
\item \code{tic} (one of "through", "in", "out", or "none") to choose a tic-mark placement/length that is different from the default through and out.
}
}
\item{pax}{list with parameters for drawing axes. See the arguments for \code{\link{axis}}. Arguments \code{side}, \code{tick} and \code{lab} can be used to indicate for which of the four axes to draw a line (side), tick-mark, and/or the tick-mark labels. The default is \code{c(1:4)} for side and \code{1:2} for the other two. If \code{side} is changed the other two default to that value. Logical argument \code{retro} can be used to use a sexagesimal notation for the labels (degrees/minutes/hemisphere) instead of the standard decimal notation}
\item{maxcell}{positive integer. Maximum number of cells to use for the plot}
\item{smooth}{logical. If \code{TRUE} the cell values are smoothed (only if a continuous legend is used)}
Expand Down

0 comments on commit 24b66f6

Please sign in to comment.