MinorTick | R Documentation |
Adds minor tick marks to an existing plot.
MinorTick(
n = 2,
side = 1,
tick.ratio = 0.5,
col = "black",
lwd = 1,
extend = 0,
...
)
n |
number of intervals in which to divide the area between major tick marks on the specified axis. Values <= 1 suppress minor tick marks. |
side |
an integer specifying on which axis the minor ticks are to be drawn on. The axis is denoted as follows: 1=below, 2=left, 3=above and 4=right. |
tick.ratio |
ratio of lengths of minor tick marks to major tick marks. The length of major tick marks is retrieved from ‘par("tcl")’. |
col |
color of the minor ticks. |
lwd |
line width for the minor ticks; defaults to 1. |
extend |
an integer specifying the number of minor ticks to be plotted
before the first and after the last major tick mark; if larger than
|
... |
further graphical parameters passed on to |
This is a modified version of the function minor.tick
from the
package Hmisc
. Main differences are i) that minor ticks are only
plotted between the positions of the existing major ticks, not additionally
at the major ticks, but extending the minor ticks beyond the first and last
major tick is optional using the extend
parameter, ii) allowing the
direct setting of the colour and the line width of the minor ticks, and iii)
that minor ticks can be also drawn on axes at the top or the right-hand side
of the plot. The latter, however, makes it necessary to call MinorTick
twice if you want to plott minor ticks on both the x and y axes on the same
plot.
Frank Harrell, Earl Bellinger, Viktor Horvath, Thomas Münch
The original version of minor.tick
is available in the
Hmisc
package from CRAN:
<https://cran.r-project.org/web/packages/Hmisc/>
plot(1 : 10)
MinorTick(n = 1) # <- no minor ticks
MinorTick()
MinorTick(side = 2, lwd = 3)
MinorTick(n = 4, side = 3)
MinorTick(n = 6, side = 4, col = 2)
# plot extended minor ticks
x <- 2 : 9
plot(x = x, y = x, axes = FALSE, xlim = c(1, 10))
par(xaxp = c(2, 9, 7))
axis(1)
axis(2)
MinorTick(n = 3, extend = 2)
# <- looks unpleasant without a bounding box
box() # better
# optional parameters that may need to be passed on include, e.g.,
# the line parameter:
plot(1 : 10, axes = FALSE, xlab = "")
axis(2)
axis(1, line = 2)
MinorTick() # <- incorrect positioning
MinorTick(line = 2) # here we go
# you need to be careful when manually setting major tick mark locations
## Not run:
plot(1 : 10, xlim = c(0, 10), axes = FALSE)
axis(1, at = seq(0.5, 9.5, 1))
MinorTick(col = "red")
# <- this will position the minor tick marks incorrectly, since
# \code{MinorTick} extracts the major tick mark positions from
# \code{xaxp} and \code{yaxp}, which are not updated by the manual setting
# in \code{axis}
## End(Not run)
# this instead works:
plot(1 : 10, xlim = c(0, 10), axes = FALSE)
par(xaxp = c(0.5, 9.5, 9))
axis(1)
MinorTick(col = "red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.