77# ' @param sides a string that controls which sides of the plot the log ticks appear on.
88# ' It can be set to a string containing any of `"trbl"`, for top, right,
99# ' 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.
1013# ' @param short a [grid::unit()] object specifying the length of the
1114# ' short tick marks
1215# ' @param mid a [grid::unit()] object specifying the length of the
4750# ' a + annotation_logticks(sides = "lr") # Log ticks for y, on left and right
4851# ' a + annotation_logticks(sides = "trbl") # All four sides
4952# '
53+ # ' a + annotation_logticks(sides = "lr", outside = TRUE) +
54+ # ' coord_cartesian(clip = "off") # Ticks outside plot
55+ # '
5056# ' # Hide the minor grid lines because they don't align with the ticks
5157# ' a + annotation_logticks(sides = "trbl") + theme(panel.grid.minor = element_blank())
5258# '
7379# ' mid = unit(3,"mm"),
7480# ' long = unit(4,"mm")
7581# ' )
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 , ... )
7985{
8086 if (! is.null(color ))
8187 colour <- color
@@ -91,6 +97,7 @@ annotation_logticks <- function(base = 10, sides = "bl", scaled = TRUE,
9197 params = list (
9298 base = base ,
9399 sides = sides ,
100+ outside = outside ,
94101 scaled = scaled ,
95102 short = short ,
96103 mid = mid ,
@@ -115,8 +122,8 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
115122 },
116123
117124 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" ))
120127 {
121128 ticks <- list ()
122129
@@ -144,6 +151,10 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
144151
145152 names(xticks )[names(xticks ) == " value" ] <- " x" # Rename to 'x' for coordinates$transform
146153 xticks <- coord $ transform(xticks , panel_params )
154+ xticks = xticks [xticks $ x < = 1 & xticks $ x > = 0 ,]
155+
156+ if (outside )
157+ xticks $ end = - xticks $ end
147158
148159 # Make the grobs
149160 if (grepl(" b" , sides )) {
@@ -179,6 +190,10 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
179190
180191 names(yticks )[names(yticks ) == " value" ] <- " y" # Rename to 'y' for coordinates$transform
181192 yticks <- coord $ transform(yticks , panel_params )
193+ yticks = yticks [yticks $ y < = 1 & yticks $ y > = 0 ,]
194+
195+ if (outside )
196+ yticks $ end = - yticks $ end
182197
183198 # Make the grobs
184199 if (grepl(" l" , sides )) {
0 commit comments