Skip to content

Commit 3cd0280

Browse files
authored
Merge branch 'master' into v3.3.0-rc
2 parents 8f2f398 + 84212b0 commit 3cd0280

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* Support graphics devices that use the `file` argument instead of `fileneame`
55
in `ggsave()` (@bwiernik, #3810)
66

7+
* Added an `outside` option to `annotation_logticks()` that places tick marks
8+
outside of the plot bounds. (#3783, @kbodwin)
9+
710
# ggplot2 3.3.0
811

912
This is a minor release but does contain a range of substantial new features,

R/annotation-logticks.r

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
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
@@ -47,6 +50,9 @@
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
#'
@@ -73,9 +79,9 @@
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)) {

R/stat-summary.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,13 @@ summarise_by_x <- function(data, summary, ...) {
226226
#' @return A data frame with columns `y`, `ymin`, and `ymax`.
227227
#' @name hmisc
228228
#' @examples
229+
#' if (requireNamespace("Hmisc", quietly = TRUE)) {
229230
#' x <- rnorm(100)
230231
#' mean_cl_boot(x)
231232
#' mean_cl_normal(x)
232233
#' mean_sdl(x)
233234
#' median_hilow(x)
235+
#' }
234236
NULL
235237

236238
wrap_hmisc <- function(fun) {

man/annotation_logticks.Rd

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/hmisc.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)