swaptick: Flip Direction of Axis Ticks

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/swaptick.R

Description

Given a single coordinate of a single axis tick, 'swaptick' flips it to the opposite side of the axis line.

'swap_ticklist' just applies 'swaptick' to a list of tick coordinates.

Both are probably useless except inside mirror_ticks.

Usage

1
2
	swaptick(tick)
	swap_ticklist(ticks)

Arguments

tick

A unit object

ticks

A unit.list object

Details

Tick coordinates for the end on the axis line are encoded as a unit containing 1npc, while coordinates for the other end are objects of the undocumented subclass unit.arithmetic, containing 1npc - axis.tick.length. For each individual tick, we leave the axis end alone and move ticks to the other side of the line by flipping the sign of the subtraction.

'swap_ticklist' just applies 'swaptick' to every tick in the list.

Value

For swap_ticklist: A unit.list object with 'swaptick' applied to each entry. For swaptick: If tick was a unit.arithmetic, a unit.arithmetic with the sign flipped. If tick was a unit, the unchanged tick.

Author(s)

Chris Black <[email protected]>

See Also

theme for more on axis.ticks, mirror_ticks for a practical application of tick-flipping.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
tick_start = unit(1, "npc")
tick_stop = tick_start - unit(0.1, "npc")

tick_start
# [1] 1npc
tick_stop
# [1] 1npc-0.1npc

swaptick(tick_start)
# 1npc
swaptick(tick_stop)
# 1npc--0.1npc

# The intended use case: invert the ticks from a whole axis at once
ax=grid::unit.c(tick_start, tick_stop, tick_start, tick_stop, tick_start, tick_stop)
ax_flipped = sapply(ax, swaptick, simplify=FALSE)
class(ax_flipped) = c("unit.list", "unit")

ax
# [1] 1npc        1npc-0.1npc 1npc        1npc-0.1npc 1npc        1npc-0.1npc
ax_flipped
# [1] 1npc         1npc--0.1npc 1npc         1npc--0.1npc 1npc         1npc--0.1npc

identical(ax_flipped, swap_ticklist(ax))
# TRUE

infotroph/ggplotTicks documentation built on May 17, 2017, 4:16 a.m.