axis: Add an Axis to a Plot (2024)

axisR Documentation

Description

Adds an axis to the current plot, allowing thespecification of the side, position, labels, and other options.

Usage

axis(side, at = NULL, labels = TRUE, tick = TRUE, line = NA, pos = NA, outer = FALSE, font = NA, lty = "solid", lwd = 1, lwd.ticks = lwd, col = NULL, col.ticks = NULL, hadj = NA, padj = NA, gap.axis = NA, ...)

Arguments

side

an integer specifying which side of the plot the axis isto be drawn on. The axis is placed as follows: 1=below,2=left, 3=above and 4=right.

at

the points at which tick-marks are to be drawn. Non-finite(infinite, NaN or NA) values are omitted. By default(when NULL) tickmark locations are computed, see‘Details’ below.

labels

this can either be a logical value specifying whether(numerical) annotations are to be made at the tickmarks, or acharacter or expression vector of labels to be placed at thetickpoints. (Other objects are coerced by as.graphicsAnnot.)If this is not logical, at should also be supplied and of thesame length. If labels is of length zero after coercion,it has the same effect as supplying TRUE.

tick

a logical value specifying whether tickmarks and an axis lineshould be drawn.

line

the number of lines into the margin at which the axis linewill be drawn, if not NA.

pos

the coordinate at which the axis line is to be drawn:if not NA this overrides the value of line.

outer

a logical value indicating whether the axis should bedrawn in the outer plot margin, rather than the standard plotmargin.

font

font for text. Defaults to par("font").

lty

line type for both the axis line and the tick marks.

lwd, lwd.ticks

line widths for the axis line and the tickmarks. Zero or negative values will suppress the line or ticks.

col, col.ticks

colors for the axis line and the tick marksrespectively. col = NULL means to use par("fg"),possibly specified inline, and col.ticks = NULL means to usewhatever color col resolved to.

hadj

adjustment (see par("adj")) for all labelsparallel (‘horizontal’) to the reading direction. Ifthis is not a finite value, the default is used (centring forstrings parallel to the axis, justification of the end nearest theaxis otherwise).

padj

adjustment for each tick label perpendicular to thereading direction. For labels parallel to the axes, padj = 0means right or top alignment, and padj = 1 means left or bottomalignment. This can be a vector given a value for each string, andwill be recycled as necessary.

If padj is not a finite value (the default), the value ofpar("las") determines the adjustment. For strings plottedperpendicular to the axis the default is to centre the string.

gap.axis

an optional (typically non-negative) numeric factor tobe multiplied with the size of an ‘m’ to determine theminimal gap between labels that are drawn, see ‘Details’.The default, NA, corresponds to 1 for tick labels drawnparallel to the axis and 0.25 otherwise, i.e., thedefault is equivalent to

 perpendicular <- function(side, las) { is.x <- (side %% 2 == 1) # is horizontal x-axis ( is.x && (las %in% 2:3)) || (!is.x && (las %in% 1:2)) } gap.axis <- if(perpendicular(side, las)) 0.25 else 1

gap.axis may typically be relevant when at = ..tick-mark positions are specified explicitly.

...

other graphical parameters may also be passed asarguments to this function, particularly, cex.axis, col.axisand font.axis for axis annotation, i.e. tick labels, mgpand xaxp or yaxp for positioning, tck ortcl for tick mark length and direction, las forvertical/horizontal label orientation, or fg instead ofcol, and xpd for clipping. See par on these.

Parameters xaxt (sides 1 and 3) and yaxt (sides 2 and4) control if the axis is plotted at all.

Note that lab will partial match to argumentlabels unless the latter is also supplied. (Since thedefault axes have already been set up by plot.window,lab will not be acted on by axis.)

Details

The axis line is drawn from the lowest to the highest value ofat, but will be clipped at the plot region. By default, onlyticks which are drawn from points within the plot region (up to atolerance for rounding error) are plotted, but the ticks and theirlabels may well extend outside the plot region. Use xpd = TRUEor xpd = NA to allow axes to extend further.

When at = NULL, pretty tick mark locations are computed internally(the same way axTicks(side) would) frompar("xaxp") or "yaxp" andpar("xlog") (or "ylog"). Note that theselocations may change if an on-screen plot is resized (for example, ifthe plot argument asp (see plot.window) is set.)

If labels is not specified, the numeric values supplied orcalculated for at are converted to character strings as if theywere a numeric vector printed by print.default(digits = 7).

The code tries hard not to draw overlapping tick labels, and so willomit labels where they would abut or overlap previously drawn labels.This can result in, for example, every other tick being labelled.The ticks are drawn left to right or bottom to top, and space atleast the size of an ‘m’, multiplied by gap.axis,is left between labels. In previous R versions, this applied onlyfor labels written parallel to the axis direction, hence notfor e.g., las = 2. Using gap.axis = -1 restores that(buggy) previous behaviour (in the perpendicular case).

If either line or pos is set, they (rather thanpar("mgp")[3]) determine the position of the axis line and tickmarks, and the tick labels are placed par("mgp")[2] furtherlines into (or towards for pos) the margin.

Several of the graphics parameters affect the way axes are drawn. Thevertical (for sides 1 and 3) positions of the axis and the tick labelsare controlled by mgp[2:3] and mex, the size anddirection of the ticks is controlled by tck and tcl andthe appearance of the tick labels by cex.axis, col.axisand font.axis with orientation controlled by las (butnot srt, unlike S which uses srt if at issupplied and las if it is not). Note that adj is notsupported and labels are always centered. See par for details.

Value

The numeric locations on the axis scale at which tick marks were drawnwhen the plot was first drawn (see ‘Details’).

This function is usually invoked for its side effect, which is to addan axis to an already existing plot.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.

See Also

Axis for a generic interface.

axTicks returns the axis tick locationscorresponding to at = NULL; pretty is more flexiblefor computing pretty tick coordinates and does not depend on(nor adapt to) the coordinate system in use.

Several graphics parameters affecting the appearance are documentedin par.

Examples

require(stats) # for rnormplot(1:4, rnorm(4), axes = FALSE)axis(1, 1:4, LETTERS[1:4])axis(2)box() #- to make it look "as usual"plot(1:7, rnorm(7), main = "axis() examples", type = "s", xaxt = "n", frame.plot = FALSE, col = "red")axis(1, 1:7, LETTERS[1:7], col.axis = "blue")# unusual options:axis(4, col = "violet", col.axis = "dark violet", lwd = 2)axis(3, col = "gold", lty = 2, lwd = 0.5)# one way to have a custom x axisplot(1:10, xaxt = "n")axis(1, xaxp = c(2, 9, 7))## Changing default gap between labels:plot(0:100, type="n", axes=FALSE, ann=FALSE)title(quote("axis(1, .., gap.axis = f)," ~~ f >= 0))axis(2, at = 5*(0:20), las = 1, gap.axis = 1/4)gaps <- c(4, 2, 1, 1/2, 1/4, 0.1, 0)chG <- paste0(ifelse(gaps == 1, "default: ", ""), "gap.axis=", formatC(gaps))jj <- seq_along(gaps)linG <- -2.5*(jj-1)for(j in jj) { isD <- gaps[j] == 1 # is default axis (1, at=5*(0:20), gap.axis = gaps[j], padj=-1, line = linG[j], col.axis = if(isD) "forest green" else 1, font.axis= 1+isD)}mtext(chG, side=1, padj=-1, line = linG -1/2, cex=3/4, col = ifelse(gaps == 1, "forest green", "blue3"))## now shrink the window (in x- and y-direction) and observe the axis labels drawn
axis: Add an Axis to a Plot (2024)

References

Top Articles
Kansas City, MO - Motorcycles For Sale - Cycle Trader
Kansas City, MO - Dirt Bike Motorcycles For Sale - Cycle Trader
San Angelo, Texas: eine Oase für Kunstliebhaber
Worcester Weather Underground
Knoxville Tennessee White Pages
Danielle Moodie-Mills Net Worth
Ffxiv Palm Chippings
Craigslist Vans
Craigslist Campers Greenville Sc
Health Benefits of Guava
The Pope's Exorcist Showtimes Near Cinemark Hollywood Movies 20
Fire Rescue 1 Login
LeBron James comes out on fire, scores first 16 points for Cavaliers in Game 2 vs. Pacers
Conduent Connect Feps Login
Mephisto Summoners War
United Dual Complete Providers
U/Apprenhensive_You8924
Exterior insulation details for a laminated timber gothic arch cabin - GreenBuildingAdvisor
Robert Deshawn Swonger Net Worth
Tu Pulga Online Utah
Unionjobsclearinghouse
Purdue 247 Football
Slim Thug’s Wealth and Wellness: A Journey Beyond Music
All Obituaries | Verkuilen-Van Deurzen Family Funeral Home | Little Chute WI funeral home and cremation
Cookie Clicker Advanced Method Unblocked
Jailfunds Send Message
Tamil Movies - Ogomovies
Die wichtigsten E-Nummern
Trust/Family Bank Contingency Plan
Missing 2023 Showtimes Near Grand Theatres - Bismarck
123Moviestvme
Six Flags Employee Pay Stubs
Dumb Money, la recensione: Paul Dano e quel film biografico sul caso GameStop
Golden Tickets
A Small Traveling Suitcase Figgerits
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
Goodwill Thrift Store & Donation Center Marietta Photos
ATM Near Me | Find The Nearest ATM Location | ATM Locator NL
Miracle Shoes Ff6
Craigslist Florida Trucks
Japanese Big Natural Boobs
Puretalkusa.com/Amac
Tedit Calamity
Memberweb Bw
6576771660
Ssc South Carolina
Fluffy Jacket Walmart
New Zero Turn Mowers For Sale Near Me
Underground Weather Tropical
Quest Diagnostics Mt Morris Appointment
Kenmore Coldspot Model 106 Light Bulb Replacement
Suzanne Olsen Swift River
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 6108

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.