4
4
# @param labels at ticks
5
5
# @param position of axis (top, bottom, left or right)
6
6
# @param range of data values
7
- guide_axis <- function (at , labels , position = " right" , theme ) {
8
- position <- match.arg(position , c(" top" , " bottom" , " right" , " left" ))
9
-
10
- # Quick fix for conflicts #297 and #118
11
- # Previously, at = NA if there is no breaks (breaks = NA).
12
- # Fix for oob bug changed so that at = numeric(0) if there is no breaks.
13
- # Temporally, at is set as NA if there is no breaks.
14
- # see also SHA: f332070fca77399a84ea7a116e8c63f6990abaf6, SHA: 2ae13ad0a856c24cab6a69b523da0936ef7a94d8
15
- if (length(at ) == 0 ) at <- NA
7
+ guide_axis <- function (at , labels , position = " right" , theme ) {
8
+ if (length(at ) == 0 )
9
+ return (zeroGrob())
16
10
17
11
at <- unit(at , " native" )
18
- length <- theme $ axis.ticks.length
19
- label_pos <- length
20
-
21
- nticks <- length(at )
12
+ position <- match.arg(position , c(" top" , " bottom" , " right" , " left" ))
22
13
23
14
zero <- unit(0 , " npc" )
24
15
one <- unit(1 , " npc" )
@@ -31,12 +22,12 @@ guide_axis <- function(at, labels, position="right", theme) {
31
22
label_x <- switch (position ,
32
23
top = ,
33
24
bottom = at ,
34
- right = label_pos ,
35
- left = one - label_pos
25
+ right = theme $ axis.ticks.length ,
26
+ left = one - theme $ axis.ticks.length
36
27
)
37
28
label_y <- switch (position ,
38
- top = label_pos ,
39
- bottom = one - label_pos ,
29
+ top = theme $ axis.ticks.length ,
30
+ bottom = one - theme $ axis.ticks.length ,
40
31
right = ,
41
32
left = at
42
33
)
@@ -62,21 +53,23 @@ guide_axis <- function(at, labels, position="right", theme) {
62
53
left = element_render(theme , " axis.line.y" , c(1 , 1 ), c(0 , 1 ), id.lengths = 2 )
63
54
)
64
55
56
+ nticks <- length(at )
57
+
65
58
ticks <- switch (position ,
66
59
top = element_render(theme , " axis.ticks.x" ,
67
60
x = rep(at , each = 2 ),
68
- y = rep(unit.c(zero , length ), nticks ),
61
+ y = rep(unit.c(zero , theme $ axis.ticks. length ), nticks ),
69
62
id.lengths = rep(2 , nticks )),
70
63
bottom = element_render(theme , " axis.ticks.x" ,
71
64
x = rep(at , each = 2 ),
72
- y = rep(unit.c(one - length , one ), nticks ),
65
+ y = rep(unit.c(one - theme $ axis.ticks. length , one ), nticks ),
73
66
id.lengths = rep(2 , nticks )),
74
67
right = element_render(theme , " axis.ticks.y" ,
75
- x = rep(unit.c(zero , length ), nticks ),
68
+ x = rep(unit.c(zero , theme $ axis.ticks. length ), nticks ),
76
69
y = rep(at , each = 2 ),
77
70
id.lengths = rep(2 , nticks )),
78
71
left = element_render(theme , " axis.ticks.y" ,
79
- x = rep(unit.c(one - length , one ), nticks ),
72
+ x = rep(unit.c(one - theme $ axis.ticks. length , one ), nticks ),
80
73
y = rep(at , each = 2 ),
81
74
id.lengths = rep(2 , nticks ))
82
75
)
@@ -86,19 +79,23 @@ guide_axis <- function(at, labels, position="right", theme) {
86
79
top = gtable_col(" axis" ,
87
80
grobs = list (labels , ticks ),
88
81
width = one ,
89
- heights = unit.c(grobHeight(labels ), label_pos )),
82
+ heights = unit.c(grobHeight(labels ), theme $ axis.ticks.length )
83
+ ),
90
84
bottom = gtable_col(" axis" ,
91
85
grobs = list (ticks , labels ),
92
86
width = one ,
93
- heights = unit.c(label_pos , grobHeight(labels ))),
87
+ heights = unit.c(theme $ axis.ticks.length , grobHeight(labels ))
88
+ ),
94
89
right = gtable_row(" axis" ,
95
90
grobs = list (ticks , labels ),
96
- widths = unit.c(label_pos , grobWidth(labels )),
97
- height = one ),
91
+ widths = unit.c(theme $ axis.ticks.length , grobWidth(labels )),
92
+ height = one
93
+ ),
98
94
left = gtable_row(" axis" ,
99
95
grobs = list (labels , ticks ),
100
- widths = unit.c(grobWidth(labels ), label_pos ),
101
- height = one )
96
+ widths = unit.c(grobWidth(labels ), theme $ axis.ticks.length ),
97
+ height = one
98
+ )
102
99
)
103
100
104
101
# Viewport for justifying the axis grob
0 commit comments