@@ -14,22 +14,30 @@ guide_axis <- function(at, labels, position = "right", theme) {
14
14
zero <- unit(0 , " npc" )
15
15
one <- unit(1 , " npc" )
16
16
17
- theme $ axis.ticks.length.x.bottom <- with(theme ,
18
- axis.ticks.length.x.bottom %|| %
19
- axis.ticks.length.x %|| %
20
- axis.ticks.length )
21
- theme $ axis.ticks.length.x.top <- with(theme ,
22
- axis.ticks.length.x.top %|| %
23
- axis.ticks.length.x %|| %
24
- axis.ticks.length )
25
- theme $ axis.ticks.length.y.left <- with(theme ,
26
- axis.ticks.length.y.left %|| %
27
- axis.ticks.length.y %|| %
28
- axis.ticks.length )
29
- theme $ axis.ticks.length.y.right <- with(theme ,
30
- axis.ticks.length.y.right %|| %
31
- axis.ticks.length.y %|| %
32
- axis.ticks.length )
17
+ theme $ axis.ticks.length.x.bottom <- with(
18
+ theme ,
19
+ axis.ticks.length.x.bottom %|| %
20
+ axis.ticks.length.x %|| %
21
+ axis.ticks.length
22
+ )
23
+ theme $ axis.ticks.length.x.top <- with(
24
+ theme ,
25
+ axis.ticks.length.x.top %|| %
26
+ axis.ticks.length.x %|| %
27
+ axis.ticks.length
28
+ )
29
+ theme $ axis.ticks.length.y.left <- with(
30
+ theme ,
31
+ axis.ticks.length.y.left %|| %
32
+ axis.ticks.length.y %|| %
33
+ axis.ticks.length
34
+ )
35
+ theme $ axis.ticks.length.y.right <- with(
36
+ theme ,
37
+ axis.ticks.length.y.right %|| %
38
+ axis.ticks.length.y %|| %
39
+ axis.ticks.length
40
+ )
33
41
34
42
label_render <- switch (position ,
35
43
top = " axis.text.x.top" , bottom = " axis.text.x.bottom" ,
@@ -74,53 +82,57 @@ guide_axis <- function(at, labels, position = "right", theme) {
74
82
75
83
ticks <- switch (position ,
76
84
top = element_render(theme , " axis.ticks.x.top" ,
77
- x = rep(at , each = 2 ),
78
- y = rep(unit.c(zero , theme $ axis.ticks.length.x.top ), nticks ),
79
- id.lengths = rep(2 , nticks )),
85
+ x = rep(at , each = 2 ),
86
+ y = rep(unit.c(zero , theme $ axis.ticks.length.x.top ), nticks ),
87
+ id.lengths = rep(2 , nticks )
88
+ ),
80
89
bottom = element_render(theme , " axis.ticks.x.bottom" ,
81
- x = rep(at , each = 2 ),
82
- y = rep(unit.c(one - theme $ axis.ticks.length.x.bottom , one ), nticks ),
83
- id.lengths = rep(2 , nticks )),
90
+ x = rep(at , each = 2 ),
91
+ y = rep(unit.c(one - theme $ axis.ticks.length.x.bottom , one ), nticks ),
92
+ id.lengths = rep(2 , nticks )
93
+ ),
84
94
right = element_render(theme , " axis.ticks.y.right" ,
85
- x = rep(unit.c(zero , theme $ axis.ticks.length.y.right ), nticks ),
86
- y = rep(at , each = 2 ),
87
- id.lengths = rep(2 , nticks )),
95
+ x = rep(unit.c(zero , theme $ axis.ticks.length.y.right ), nticks ),
96
+ y = rep(at , each = 2 ),
97
+ id.lengths = rep(2 , nticks )
98
+ ),
88
99
left = element_render(theme , " axis.ticks.y.left" ,
89
- x = rep(unit.c(one - theme $ axis.ticks.length.y.left , one ), nticks ),
90
- y = rep(at , each = 2 ),
91
- id.lengths = rep(2 , nticks ))
100
+ x = rep(unit.c(one - theme $ axis.ticks.length.y.left , one ), nticks ),
101
+ y = rep(at , each = 2 ),
102
+ id.lengths = rep(2 , nticks )
103
+ )
92
104
)
93
105
94
106
# Create the gtable for the ticks + labels
95
107
gt <- switch (position ,
96
- top = gtable_col(" axis" ,
97
- grobs = list (labels , ticks ),
98
- width = one ,
108
+ top = gtable_col(" axis" ,
109
+ grobs = list (labels , ticks ),
110
+ width = one ,
99
111
heights = unit.c(grobHeight(labels ), theme $ axis.ticks.length.x.top )
100
112
),
101
113
bottom = gtable_col(" axis" ,
102
- grobs = list (ticks , labels ),
103
- width = one ,
114
+ grobs = list (ticks , labels ),
115
+ width = one ,
104
116
heights = unit.c(theme $ axis.ticks.length.x.bottom , grobHeight(labels ))
105
117
),
106
- right = gtable_row(" axis" ,
107
- grobs = list (ticks , labels ),
108
- widths = unit.c(theme $ axis.ticks.length.y.right , grobWidth(labels )),
109
- height = one
118
+ right = gtable_row(" axis" ,
119
+ grobs = list (ticks , labels ),
120
+ widths = unit.c(theme $ axis.ticks.length.y.right , grobWidth(labels )),
121
+ height = one
110
122
),
111
- left = gtable_row(" axis" ,
112
- grobs = list (labels , ticks ),
113
- widths = unit.c(grobWidth(labels ), theme $ axis.ticks.length.y.left ),
114
- height = one
123
+ left = gtable_row(" axis" ,
124
+ grobs = list (labels , ticks ),
125
+ widths = unit.c(grobWidth(labels ), theme $ axis.ticks.length.y.left ),
126
+ height = one
115
127
)
116
128
)
117
129
118
130
# Viewport for justifying the axis grob
119
131
justvp <- switch (position ,
120
- top = viewport(y = 0 , just = " bottom" , height = gtable_height(gt )),
121
- bottom = viewport(y = 1 , just = " top" , height = gtable_height(gt )),
122
- right = viewport(x = 0 , just = " left" , width = gtable_width(gt )),
123
- left = viewport(x = 1 , just = " right" , width = gtable_width(gt ))
132
+ top = viewport(y = 0 , just = " bottom" , height = gtable_height(gt )),
133
+ bottom = viewport(y = 1 , just = " top" , height = gtable_height(gt )),
134
+ right = viewport(x = 0 , just = " left" , width = gtable_width(gt )),
135
+ left = viewport(x = 1 , just = " right" , width = gtable_width(gt ))
124
136
)
125
137
126
138
absoluteGrob(
0 commit comments