7
7
# ' @param sides a string that controls which sides of the plot the log ticks appear on.
8
8
# ' It can be set to a string containing any of `"trbl"`, for top, right,
9
9
# ' bottom, and left.
10
+ # ' @param outside logical that controls whether to move the log ticks outside
11
+ # ' of the plot area. Default is off (`FALSE`). You will also need to use
12
+ # ' `coord_cartesian(clip = "off")`. See examples.
10
13
# ' @param short a [grid::unit()] object specifying the length of the
11
14
# ' short tick marks
12
15
# ' @param mid a [grid::unit()] object specifying the length of the
47
50
# ' a + annotation_logticks(sides = "lr") # Log ticks for y, on left and right
48
51
# ' a + annotation_logticks(sides = "trbl") # All four sides
49
52
# '
53
+ # ' a + annotation_logticks(sides = "lr", outside = TRUE) +
54
+ # ' coord_cartesian(clip = "off") # Ticks outside plot
55
+ # '
50
56
# ' # Hide the minor grid lines because they don't align with the ticks
51
57
# ' a + annotation_logticks(sides = "trbl") + theme(panel.grid.minor = element_blank())
52
58
# '
73
79
# ' mid = unit(3,"mm"),
74
80
# ' long = unit(4,"mm")
75
81
# ' )
76
- annotation_logticks <- function (base = 10 , sides = " bl" , scaled = TRUE ,
77
- short = unit(0.1 , " cm" ), mid = unit(0.2 , " cm" ), long = unit(0.3 , " cm" ),
78
- colour = " black" , size = 0.5 , linetype = 1 , alpha = 1 , color = NULL , ... )
82
+ annotation_logticks <- function (base = 10 , sides = " bl" , outside = FALSE , scaled = TRUE ,
83
+ short = unit(0.1 , " cm" ), mid = unit(0.2 , " cm" ), long = unit(0.3 , " cm" ),
84
+ colour = " black" , size = 0.5 , linetype = 1 , alpha = 1 , color = NULL , ... )
79
85
{
80
86
if (! is.null(color ))
81
87
colour <- color
@@ -91,6 +97,7 @@ annotation_logticks <- function(base = 10, sides = "bl", scaled = TRUE,
91
97
params = list (
92
98
base = base ,
93
99
sides = sides ,
100
+ outside = outside ,
94
101
scaled = scaled ,
95
102
short = short ,
96
103
mid = mid ,
@@ -115,8 +122,8 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
115
122
},
116
123
117
124
draw_panel = function (data , panel_params , coord , base = 10 , sides = " bl" ,
118
- scaled = TRUE , short = unit( 0.1 , " cm " ), mid = unit(0.2 , " cm" ),
119
- long = unit(0.3 , " cm" ))
125
+ outside = FALSE , scaled = TRUE , short = unit(0.1 , " cm" ),
126
+ mid = unit( 0.2 , " cm " ), long = unit(0.3 , " cm" ))
120
127
{
121
128
ticks <- list ()
122
129
@@ -144,6 +151,10 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
144
151
145
152
names(xticks )[names(xticks ) == " value" ] <- " x" # Rename to 'x' for coordinates$transform
146
153
xticks <- coord $ transform(xticks , panel_params )
154
+ xticks = xticks [xticks $ x < = 1 & xticks $ x > = 0 ,]
155
+
156
+ if (outside )
157
+ xticks $ end = - xticks $ end
147
158
148
159
# Make the grobs
149
160
if (grepl(" b" , sides )) {
@@ -179,6 +190,10 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
179
190
180
191
names(yticks )[names(yticks ) == " value" ] <- " y" # Rename to 'y' for coordinates$transform
181
192
yticks <- coord $ transform(yticks , panel_params )
193
+ yticks = yticks [yticks $ y < = 1 & yticks $ y > = 0 ,]
194
+
195
+ if (outside )
196
+ yticks $ end = - yticks $ end
182
197
183
198
# Make the grobs
184
199
if (grepl(" l" , sides )) {
0 commit comments