From 8340ec76fdaafe153713f1a2672ac786e1fdc3ee Mon Sep 17 00:00:00 2001 From: Rasmus Date: Thu, 11 Oct 2018 17:28:34 +0200 Subject: [PATCH 01/12] theme: Add different ticks length for different axes --- NEWS.md | 4 ++ R/guides-axis.r | 31 ++++++++----- R/theme-defaults.r | 12 +++++ R/theme-elements.r | 6 +++ R/theme.r | 15 +++++- man/facet_wrap.Rd | 2 +- man/scale_brewer.Rd | 8 ++-- man/scale_gradient.Rd | 2 +- man/scale_grey.Rd | 4 +- man/scale_viridis.Rd | 2 +- man/theme.Rd | 10 +++- tests/figs/themes/ticks_length.svg | 74 ++++++++++++++++++++++++++++++ tests/testthat/test-theme.r | 17 +++++++ 13 files changed, 162 insertions(+), 25 deletions(-) create mode 100644 tests/figs/themes/ticks_length.svg diff --git a/NEWS.md b/NEWS.md index 301bb6d3a8..9f297b74c7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -104,6 +104,10 @@ This is a minor release and breaking changes have been kept to a minimum. End us `nlevel`, an alias for `scaled`, to better match the syntax of `stat_bin()` (@bjreisman, #2679). +* New theme elements allowing different ticks lengths for each + axis. For instance, this can be used to have inwards ticks on the + x-axis (`axis.ticks.length.x`) and and outwards ticks on the + y-axis (`axis.ticks.length.y`). (@pank, #1319) # ggplot2 3.0.0 diff --git a/R/guides-axis.r b/R/guides-axis.r index 836c11eee6..2048617a83 100644 --- a/R/guides-axis.r +++ b/R/guides-axis.r @@ -14,6 +14,13 @@ guide_axis <- function(at, labels, position = "right", theme) { zero <- unit(0, "npc") one <- unit(1, "npc") + theme$axis.ticks.length.x <- theme$axis.ticks.length.x %||% theme$axis.ticks.length + theme$axis.ticks.length.x.bottom <- theme$axis.ticks.length.x.bottom %||% theme$axis.ticks.length.x + theme$axis.ticks.length.x.top <- theme$axis.ticks.length.x.top %||% theme$axis.ticks.length.x + theme$axis.ticks.length.y <- theme$axis.ticks.length.y %||% theme$axis.ticks.length + theme$axis.ticks.length.y.left <- theme$axis.ticks.length.y.left %||% theme$axis.ticks.length.y + theme$axis.ticks.length.y.right <- theme$axis.ticks.length.y.right %||% theme$axis.ticks.length.y + label_render <- switch(position, top = "axis.text.x.top", bottom = "axis.text.x.bottom", left = "axis.text.y.left", right = "axis.text.y.right" @@ -22,12 +29,12 @@ guide_axis <- function(at, labels, position = "right", theme) { label_x <- switch(position, top = , bottom = at, - right = theme$axis.ticks.length, - left = one - theme$axis.ticks.length + right = theme$axis.ticks.length.y.right, + left = one - theme$axis.ticks.length.y.left ) label_y <- switch(position, - top = theme$axis.ticks.length, - bottom = one - theme$axis.ticks.length, + top = theme$axis.ticks.length.x.top, + bottom = one - theme$axis.ticks.length.x.bottom, right = , left = at ) @@ -58,18 +65,18 @@ guide_axis <- function(at, labels, position = "right", theme) { ticks <- switch(position, top = element_render(theme, "axis.ticks.x.top", x = rep(at, each = 2), - y = rep(unit.c(zero, theme$axis.ticks.length), nticks), + y = rep(unit.c(zero, theme$axis.ticks.length.x.top), nticks), id.lengths = rep(2, nticks)), bottom = element_render(theme, "axis.ticks.x.bottom", x = rep(at, each = 2), - y = rep(unit.c(one - theme$axis.ticks.length, one), nticks), + y = rep(unit.c(one - theme$axis.ticks.length.x.bottom, one), nticks), id.lengths = rep(2, nticks)), right = element_render(theme, "axis.ticks.y.right", - x = rep(unit.c(zero, theme$axis.ticks.length), nticks), + x = rep(unit.c(zero, theme$axis.ticks.length.y.right), nticks), y = rep(at, each = 2), id.lengths = rep(2, nticks)), left = element_render(theme, "axis.ticks.y.left", - x = rep(unit.c(one - theme$axis.ticks.length, one), nticks), + x = rep(unit.c(one - theme$axis.ticks.length.y.left, one), nticks), y = rep(at, each = 2), id.lengths = rep(2, nticks)) ) @@ -79,21 +86,21 @@ guide_axis <- function(at, labels, position = "right", theme) { top = gtable_col("axis", grobs = list(labels, ticks), width = one, - heights = unit.c(grobHeight(labels), theme$axis.ticks.length) + heights = unit.c(grobHeight(labels), theme$axis.ticks.length.x.top) ), bottom = gtable_col("axis", grobs = list(ticks, labels), width = one, - heights = unit.c(theme$axis.ticks.length, grobHeight(labels)) + heights = unit.c(theme$axis.ticks.length.x.bottom, grobHeight(labels)) ), right = gtable_row("axis", grobs = list(ticks, labels), - widths = unit.c(theme$axis.ticks.length, grobWidth(labels)), + widths = unit.c(theme$axis.ticks.length.y.right, grobWidth(labels)), height = one ), left = gtable_row("axis", grobs = list(labels, ticks), - widths = unit.c(grobWidth(labels), theme$axis.ticks.length), + widths = unit.c(grobWidth(labels), theme$axis.ticks.length.y.left), height = one ) ) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 7719744360..dd120e61aa 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -139,6 +139,12 @@ theme_grey <- function(base_size = 11, base_family = "", axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line / 2), hjust = 0), axis.ticks = element_line(colour = "grey20"), axis.ticks.length = unit(half_line / 2, "pt"), + axis.ticks.length.x = NULL, + axis.ticks.length.x.top = NULL, + axis.ticks.length.x.bottom = NULL, + axis.ticks.length.y = NULL, + axis.ticks.length.y.left = NULL, + axis.ticks.length.y.right = NULL, axis.title.x = element_text( margin = margin(t = half_line / 2), vjust = 1 @@ -528,6 +534,12 @@ theme_test <- function(base_size = 11, base_family = "", axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line / 2), hjust = 0), axis.ticks = element_line(colour = "grey20"), axis.ticks.length = unit(half_line / 2, "pt"), + axis.ticks.length.x = NULL, + axis.ticks.length.x.top = NULL, + axis.ticks.length.x.bottom = NULL, + axis.ticks.length.y = NULL, + axis.ticks.length.y.left = NULL, + axis.ticks.length.y.right = NULL, axis.title.x = element_text( margin = margin(t = half_line / 2), vjust = 1 diff --git a/R/theme-elements.r b/R/theme-elements.r index 761ca3fd21..88e3515332 100644 --- a/R/theme-elements.r +++ b/R/theme-elements.r @@ -286,6 +286,12 @@ el_def <- function(class = NULL, inherit = NULL, description = NULL) { axis.text.y.left = el_def("element_text", "axis.text.y"), axis.text.y.right = el_def("element_text", "axis.text.y"), axis.ticks.length = el_def("unit"), + axis.ticks.length.x = el_def("unit", "axis.ticks.length"), + axis.ticks.length.x.top = el_def("unit", "axis.ticks.length.x"), + axis.ticks.length.x.bottom = el_def("unit", "axis.ticks.length.x"), + axis.ticks.length.y = el_def("unit", "axis.ticks.length"), + axis.ticks.length.y.left = el_def("unit", "axis.ticks.length.y"), + axis.ticks.length.y.right = el_def("unit", "axis.ticks.length.y"), axis.ticks.x = el_def("element_line", "axis.ticks"), axis.ticks.x.top = el_def("element_line", "axis.ticks.x"), axis.ticks.x.bottom = el_def("element_line", "axis.ticks.x"), diff --git a/R/theme.r b/R/theme.r index 602b34144c..80c1f4f193 100644 --- a/R/theme.r +++ b/R/theme.r @@ -47,7 +47,8 @@ #' `axis.ticks.y.left`, `axis.ticks.y.right`). `axis.ticks.*.*` inherits from #' `axis.ticks.*` which inherits from `axis.ticks`, which in turn inherits #' from `line` -#' @param axis.ticks.length length of tick marks (`unit`) +#' @param axis.ticks.length,axis.ticks.length.x,axis.ticks.length.x.top,axis.ticks.length.x.bottom,axis.ticks.length.y,axis.ticks.length.y.left,axis.ticks.length.y.right +#' length of tick marks (`unit`) #' @param axis.line,axis.line.x,axis.line.x.top,axis.line.x.bottom,axis.line.y,axis.line.y.left,axis.line.y.right #' lines along axes ([element_line()]). Specify lines along all axes (`axis.line`), #' lines for each plane (using `axis.line.x` or `axis.line.y`), or individually @@ -195,7 +196,11 @@ #' p1 + theme(axis.line = element_line(size = 3, colour = "grey80")) #' p1 + theme(axis.text = element_text(colour = "blue")) #' p1 + theme(axis.ticks = element_line(size = 2)) -#' p1 + theme(axis.ticks.length = unit(.25, "cm")) +#' p1 + theme( +#' axis.ticks.length.y = unit(.25, "cm"), +#' axis.ticks.length.x = unit(-.25, "cm"), +#' axis.text.x=element_text(margin=margin(t=8)) +#' ) #' p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) #' #' \donttest{ @@ -275,6 +280,12 @@ theme <- function(line, axis.ticks.y.left, axis.ticks.y.right, axis.ticks.length, + axis.ticks.length.x, + axis.ticks.length.x.top, + axis.ticks.length.x.bottom, + axis.ticks.length.y, + axis.ticks.length.y.left, + axis.ticks.length.y.right, axis.line, axis.line.x, axis.line.x.top, diff --git a/man/facet_wrap.Rd b/man/facet_wrap.Rd index 4621dfe47b..63776fa8e9 100644 --- a/man/facet_wrap.Rd +++ b/man/facet_wrap.Rd @@ -16,7 +16,7 @@ The variables can be named (the names are passed to \code{labeller}). For compatibility with the classic interface, can also be a formula or character vector. Use either a one sided formula, `~a \itemize{ -\item b\code{, or a character vector,}c("a", "b")`. +\item b\code{, or a character vector, }c("a", "b")`. }} \item{nrow, ncol}{Number of rows and columns.} diff --git a/man/scale_brewer.Rd b/man/scale_brewer.Rd index feb4299834..b12923bdc0 100644 --- a/man/scale_brewer.Rd +++ b/man/scale_brewer.Rd @@ -33,9 +33,9 @@ limits, breaks, labels and so forth.} \item{palette}{If a string, will use that named palette. If a number, will index into the list of palettes of appropriate \code{type}} -\item{direction}{Sets the order of colours in the scale. If 1, the default, -colours are as output by \code{\link[RColorBrewer:brewer.pal]{RColorBrewer::brewer.pal()}}. If -1, the -order of colours is reversed.} +\item{direction}{Sets the order of colors in the scale. If 1, the default, +colors are as output by \code{\link[RColorBrewer]{brewer.pal}}. If -1, the +order of colors is reversed.} \item{aesthetics}{Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with. This can be useful, for @@ -44,7 +44,7 @@ same time, via \code{aesthetics = c("colour", "fill")}.} \item{values}{if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the -\code{colours} vector. See \code{\link[=rescale]{rescale()}} for a convenience function +\code{colours} vector. See \code{\link{rescale}} for a convience function to map an arbitrary range to between 0 and 1.} \item{space}{colour space in which to calculate gradient. Must be "Lab" - diff --git a/man/scale_gradient.Rd b/man/scale_gradient.Rd index 31cca12add..f41cb2b496 100644 --- a/man/scale_gradient.Rd +++ b/man/scale_gradient.Rd @@ -130,7 +130,7 @@ Defaults to 0.} \item{values}{if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the -\code{colours} vector. See \code{\link[=rescale]{rescale()}} for a convenience function +\code{colours} vector. See \code{\link{rescale}} for a convience function to map an arbitrary range to between 0 and 1.} } \description{ diff --git a/man/scale_grey.Rd b/man/scale_grey.Rd index cc75334ada..b2b2d55a22 100644 --- a/man/scale_grey.Rd +++ b/man/scale_grey.Rd @@ -66,9 +66,9 @@ scales, "top" or "bottom" for horizontal scales} \item{super}{The super class to use for the constructed scale} }} -\item{start}{grey value at low end of palette} +\item{start}{gray value at low end of palette} -\item{end}{grey value at high end of palette} +\item{end}{gray value at high end of palette} \item{na.value}{Colour to use for missing values} diff --git a/man/scale_viridis.Rd b/man/scale_viridis.Rd index 621aa8c6f3..1043472c27 100644 --- a/man/scale_viridis.Rd +++ b/man/scale_viridis.Rd @@ -50,7 +50,7 @@ same time, via \code{aesthetics = c("colour", "fill")}.} \item{values}{if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the -\code{colours} vector. See \code{\link[=rescale]{rescale()}} for a convenience function +\code{colours} vector. See \code{\link{rescale}} for a convience function to map an arbitrary range to between 0 and 1.} \item{space}{colour space in which to calculate gradient. Must be "Lab" - diff --git a/man/theme.Rd b/man/theme.Rd index cc99c50f5b..626c852985 100644 --- a/man/theme.Rd +++ b/man/theme.Rd @@ -10,6 +10,8 @@ theme(line, rect, text, title, aspect.ratio, axis.title, axis.title.x, axis.text.x.bottom, axis.text.y, axis.text.y.left, axis.text.y.right, axis.ticks, axis.ticks.x, axis.ticks.x.top, axis.ticks.x.bottom, axis.ticks.y, axis.ticks.y.left, axis.ticks.y.right, axis.ticks.length, + axis.ticks.length.x, axis.ticks.length.x.top, axis.ticks.length.x.bottom, + axis.ticks.length.y, axis.ticks.length.y.left, axis.ticks.length.y.right, axis.line, axis.line.x, axis.line.x.top, axis.line.x.bottom, axis.line.y, axis.line.y.left, axis.line.y.right, legend.background, legend.margin, legend.spacing, legend.spacing.x, legend.spacing.y, legend.key, @@ -60,7 +62,7 @@ for each axis (using \code{axis.ticks.x.bottom}, \code{axis.ticks.x.top}, \code{axis.ticks.*} which inherits from \code{axis.ticks}, which in turn inherits from \code{line}} -\item{axis.ticks.length}{length of tick marks (\code{unit})} +\item{axis.ticks.length, axis.ticks.length.x, axis.ticks.length.x.top, axis.ticks.length.x.bottom, axis.ticks.length.y, axis.ticks.length.y.left, axis.ticks.length.y.right}{length of tick marks (\code{unit})} \item{axis.line, axis.line.x, axis.line.x.top, axis.line.x.bottom, axis.line.y, axis.line.y.left, axis.line.y.right}{lines along axes (\code{\link[=element_line]{element_line()}}). Specify lines along all axes (\code{axis.line}), lines for each plane (using \code{axis.line.x} or \code{axis.line.y}), or individually @@ -252,7 +254,11 @@ p1 + theme( p1 + theme(axis.line = element_line(size = 3, colour = "grey80")) p1 + theme(axis.text = element_text(colour = "blue")) p1 + theme(axis.ticks = element_line(size = 2)) -p1 + theme(axis.ticks.length = unit(.25, "cm")) +p1 + theme( + axis.ticks.length.y = unit(.25, "cm"), + axis.ticks.length.x = unit(-.25, "cm"), + axis.text.x=element_text(margin=margin(t=8)) +) p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) \donttest{ diff --git a/tests/figs/themes/ticks_length.svg b/tests/figs/themes/ticks_length.svg new file mode 100644 index 0000000000..54c82ae3b1 --- /dev/null +++ b/tests/figs/themes/ticks_length.svg @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.5 +5.0 +7.5 +10.0 + + + + +2.5 +5.0 +7.5 +10.0 + + + + + + + + +2.5 +5.0 +7.5 +10.0 + + + + +2.5 +5.0 +7.5 +10.0 +1:10 +1:10 +1:10 +1:10 + diff --git a/tests/testthat/test-theme.r b/tests/testthat/test-theme.r index 63cc5a04c3..a4690d3b80 100644 --- a/tests/testthat/test-theme.r +++ b/tests/testthat/test-theme.r @@ -354,6 +354,23 @@ test_that("axes can be styled independently", { expect_doppelganger("axes_styling", plot) }) +test_that("axes ticks can have independent lengths", { + plot <- ggplot() + + theme_test() + + geom_point(aes(1:10, 1:10)) + + scale_x_continuous(sec.axis = dup_axis()) + + scale_y_continuous(sec.axis = dup_axis()) + + theme( + axis.ticks.length.x.top = unit(-.5, "cm"), + axis.ticks.length.x.bottom = unit(-.25, "cm"), + axis.ticks.length.y.left = unit(.25, "cm"), + axis.ticks.length.y.right = unit(.5, "cm"), + axis.text.x.bottom = element_text(margin=margin(t=.5, unit="cm")), + axis.text.x.top = element_text(margin=margin(b=.75, unit="cm")) + ) + expect_doppelganger("ticks_length", plot) +}) + test_that("strips can be styled independently", { df <- data.frame(x = 1:2, y = 1:2) plot <- ggplot(df, aes(x, y)) + From 4ee8b131a21d9b0e5e3e98fb8dd0745f2ade9c36 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Oct 2018 10:28:19 +0200 Subject: [PATCH 02/12] guides-axis: make assignment a bit more elegant --- R/guides-axis.r | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/R/guides-axis.r b/R/guides-axis.r index 2048617a83..2dd6d1cc66 100644 --- a/R/guides-axis.r +++ b/R/guides-axis.r @@ -14,12 +14,22 @@ guide_axis <- function(at, labels, position = "right", theme) { zero <- unit(0, "npc") one <- unit(1, "npc") - theme$axis.ticks.length.x <- theme$axis.ticks.length.x %||% theme$axis.ticks.length - theme$axis.ticks.length.x.bottom <- theme$axis.ticks.length.x.bottom %||% theme$axis.ticks.length.x - theme$axis.ticks.length.x.top <- theme$axis.ticks.length.x.top %||% theme$axis.ticks.length.x - theme$axis.ticks.length.y <- theme$axis.ticks.length.y %||% theme$axis.ticks.length - theme$axis.ticks.length.y.left <- theme$axis.ticks.length.y.left %||% theme$axis.ticks.length.y - theme$axis.ticks.length.y.right <- theme$axis.ticks.length.y.right %||% theme$axis.ticks.length.y + theme$axis.ticks.length.x.bottom <- with(theme, + axis.ticks.length.x.bottom %||% + axis.ticks.length.x %||% + axis.ticks.length) + theme$axis.ticks.length.x.top <- with(theme, + axis.ticks.length.x.top %||% + axis.ticks.length.x %||% + axis.ticks.length) + theme$axis.ticks.length.y.left <- with(theme, + axis.ticks.length.y.left %||% + axis.ticks.length.y %||% + axis.ticks.length) + theme$axis.ticks.length.y.right <- with(theme, + axis.ticks.length.y.right %||% + axis.ticks.length.y %||% + axis.ticks.length) label_render <- switch(position, top = "axis.text.x.top", bottom = "axis.text.x.bottom", From 456e74291474e833fab47d99ed53ae5ffdad8e14 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Oct 2018 10:30:56 +0200 Subject: [PATCH 03/12] styler changes to adhere to tidyverse style guide --- R/guides-axis.r | 102 ++++++++++++++++++++---------------- R/theme-defaults.r | 14 ++--- R/theme-elements.r | 12 ++--- tests/testthat/test-theme.r | 14 ++--- 4 files changed, 77 insertions(+), 65 deletions(-) diff --git a/R/guides-axis.r b/R/guides-axis.r index 2dd6d1cc66..10ad91cfd2 100644 --- a/R/guides-axis.r +++ b/R/guides-axis.r @@ -14,22 +14,30 @@ guide_axis <- function(at, labels, position = "right", theme) { zero <- unit(0, "npc") one <- unit(1, "npc") - theme$axis.ticks.length.x.bottom <- with(theme, - axis.ticks.length.x.bottom %||% - axis.ticks.length.x %||% - axis.ticks.length) - theme$axis.ticks.length.x.top <- with(theme, - axis.ticks.length.x.top %||% - axis.ticks.length.x %||% - axis.ticks.length) - theme$axis.ticks.length.y.left <- with(theme, - axis.ticks.length.y.left %||% - axis.ticks.length.y %||% - axis.ticks.length) - theme$axis.ticks.length.y.right <- with(theme, - axis.ticks.length.y.right %||% - axis.ticks.length.y %||% - axis.ticks.length) + theme$axis.ticks.length.x.bottom <- with( + theme, + axis.ticks.length.x.bottom %||% + axis.ticks.length.x %||% + axis.ticks.length + ) + theme$axis.ticks.length.x.top <- with( + theme, + axis.ticks.length.x.top %||% + axis.ticks.length.x %||% + axis.ticks.length + ) + theme$axis.ticks.length.y.left <- with( + theme, + axis.ticks.length.y.left %||% + axis.ticks.length.y %||% + axis.ticks.length + ) + theme$axis.ticks.length.y.right <- with( + theme, + axis.ticks.length.y.right %||% + axis.ticks.length.y %||% + axis.ticks.length + ) label_render <- switch(position, top = "axis.text.x.top", bottom = "axis.text.x.bottom", @@ -74,53 +82,57 @@ guide_axis <- function(at, labels, position = "right", theme) { ticks <- switch(position, top = element_render(theme, "axis.ticks.x.top", - x = rep(at, each = 2), - y = rep(unit.c(zero, theme$axis.ticks.length.x.top), nticks), - id.lengths = rep(2, nticks)), + x = rep(at, each = 2), + y = rep(unit.c(zero, theme$axis.ticks.length.x.top), nticks), + id.lengths = rep(2, nticks) + ), bottom = element_render(theme, "axis.ticks.x.bottom", - x = rep(at, each = 2), - y = rep(unit.c(one - theme$axis.ticks.length.x.bottom, one), nticks), - id.lengths = rep(2, nticks)), + x = rep(at, each = 2), + y = rep(unit.c(one - theme$axis.ticks.length.x.bottom, one), nticks), + id.lengths = rep(2, nticks) + ), right = element_render(theme, "axis.ticks.y.right", - x = rep(unit.c(zero, theme$axis.ticks.length.y.right), nticks), - y = rep(at, each = 2), - id.lengths = rep(2, nticks)), + x = rep(unit.c(zero, theme$axis.ticks.length.y.right), nticks), + y = rep(at, each = 2), + id.lengths = rep(2, nticks) + ), left = element_render(theme, "axis.ticks.y.left", - x = rep(unit.c(one - theme$axis.ticks.length.y.left, one), nticks), - y = rep(at, each = 2), - id.lengths = rep(2, nticks)) + x = rep(unit.c(one - theme$axis.ticks.length.y.left, one), nticks), + y = rep(at, each = 2), + id.lengths = rep(2, nticks) + ) ) # Create the gtable for the ticks + labels gt <- switch(position, - top = gtable_col("axis", - grobs = list(labels, ticks), - width = one, + top = gtable_col("axis", + grobs = list(labels, ticks), + width = one, heights = unit.c(grobHeight(labels), theme$axis.ticks.length.x.top) ), bottom = gtable_col("axis", - grobs = list(ticks, labels), - width = one, + grobs = list(ticks, labels), + width = one, heights = unit.c(theme$axis.ticks.length.x.bottom, grobHeight(labels)) ), - right = gtable_row("axis", - grobs = list(ticks, labels), - widths = unit.c(theme$axis.ticks.length.y.right, grobWidth(labels)), - height = one + right = gtable_row("axis", + grobs = list(ticks, labels), + widths = unit.c(theme$axis.ticks.length.y.right, grobWidth(labels)), + height = one ), - left = gtable_row("axis", - grobs = list(labels, ticks), - widths = unit.c(grobWidth(labels), theme$axis.ticks.length.y.left), - height = one + left = gtable_row("axis", + grobs = list(labels, ticks), + widths = unit.c(grobWidth(labels), theme$axis.ticks.length.y.left), + height = one ) ) # Viewport for justifying the axis grob justvp <- switch(position, - top = viewport(y = 0, just = "bottom", height = gtable_height(gt)), - bottom = viewport(y = 1, just = "top", height = gtable_height(gt)), - right = viewport(x = 0, just = "left", width = gtable_width(gt)), - left = viewport(x = 1, just = "right", width = gtable_width(gt)) + top = viewport(y = 0, just = "bottom", height = gtable_height(gt)), + bottom = viewport(y = 1, just = "top", height = gtable_height(gt)), + right = viewport(x = 0, just = "left", width = gtable_width(gt)), + left = viewport(x = 1, just = "right", width = gtable_width(gt)) ) absoluteGrob( diff --git a/R/theme-defaults.r b/R/theme-defaults.r index dd120e61aa..31ba8eedc0 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -138,13 +138,10 @@ theme_grey <- function(base_size = 11, base_family = "", axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1), axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line / 2), hjust = 0), axis.ticks = element_line(colour = "grey20"), - axis.ticks.length = unit(half_line / 2, "pt"), - axis.ticks.length.x = NULL, - axis.ticks.length.x.top = NULL, + axis.ticks.length = unit(half_line / 2, "pt"), + axis.ticks.length.x = NULL, + axis.ticks.length.x.top = NULL, axis.ticks.length.x.bottom = NULL, - axis.ticks.length.y = NULL, - axis.ticks.length.y.left = NULL, - axis.ticks.length.y.right = NULL, axis.title.x = element_text( margin = margin(t = half_line / 2), vjust = 1 @@ -158,6 +155,9 @@ theme_grey <- function(base_size = 11, base_family = "", margin = margin(r = half_line / 2), vjust = 1 ), + axis.ticks.length.y = NULL, + axis.ticks.length.y.left = NULL, + axis.ticks.length.y.right = NULL, axis.title.y.right = element_text( angle = -90, margin = margin(l = half_line / 2), @@ -533,7 +533,7 @@ theme_test <- function(base_size = 11, base_family = "", axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1), axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line / 2), hjust = 0), axis.ticks = element_line(colour = "grey20"), - axis.ticks.length = unit(half_line / 2, "pt"), + axis.ticks.length = unit(half_line / 2, "pt"), axis.ticks.length.x = NULL, axis.ticks.length.x.top = NULL, axis.ticks.length.x.bottom = NULL, diff --git a/R/theme-elements.r b/R/theme-elements.r index 88e3515332..9804827a76 100644 --- a/R/theme-elements.r +++ b/R/theme-elements.r @@ -285,15 +285,15 @@ el_def <- function(class = NULL, inherit = NULL, description = NULL) { axis.text.y = el_def("element_text", "axis.text"), axis.text.y.left = el_def("element_text", "axis.text.y"), axis.text.y.right = el_def("element_text", "axis.text.y"), - axis.ticks.length = el_def("unit"), - axis.ticks.length.x = el_def("unit", "axis.ticks.length"), - axis.ticks.length.x.top = el_def("unit", "axis.ticks.length.x"), + axis.ticks.length = el_def("unit"), + axis.ticks.length.x = el_def("unit", "axis.ticks.length"), + axis.ticks.length.x.top = el_def("unit", "axis.ticks.length.x"), axis.ticks.length.x.bottom = el_def("unit", "axis.ticks.length.x"), - axis.ticks.length.y = el_def("unit", "axis.ticks.length"), - axis.ticks.length.y.left = el_def("unit", "axis.ticks.length.y"), - axis.ticks.length.y.right = el_def("unit", "axis.ticks.length.y"), axis.ticks.x = el_def("element_line", "axis.ticks"), axis.ticks.x.top = el_def("element_line", "axis.ticks.x"), + axis.ticks.length.y = el_def("unit", "axis.ticks.length"), + axis.ticks.length.y.left = el_def("unit", "axis.ticks.length.y"), + axis.ticks.length.y.right = el_def("unit", "axis.ticks.length.y"), axis.ticks.x.bottom = el_def("element_line", "axis.ticks.x"), axis.ticks.y = el_def("element_line", "axis.ticks"), axis.ticks.y.left = el_def("element_line", "axis.ticks.y"), diff --git a/tests/testthat/test-theme.r b/tests/testthat/test-theme.r index a4690d3b80..fec7544308 100644 --- a/tests/testthat/test-theme.r +++ b/tests/testthat/test-theme.r @@ -361,13 +361,13 @@ test_that("axes ticks can have independent lengths", { scale_x_continuous(sec.axis = dup_axis()) + scale_y_continuous(sec.axis = dup_axis()) + theme( - axis.ticks.length.x.top = unit(-.5, "cm"), - axis.ticks.length.x.bottom = unit(-.25, "cm"), - axis.ticks.length.y.left = unit(.25, "cm"), - axis.ticks.length.y.right = unit(.5, "cm"), - axis.text.x.bottom = element_text(margin=margin(t=.5, unit="cm")), - axis.text.x.top = element_text(margin=margin(b=.75, unit="cm")) - ) + axis.ticks.length.x.top = unit(-.5, "cm"), + axis.ticks.length.x.bottom = unit(-.25, "cm"), + axis.ticks.length.y.left = unit(.25, "cm"), + axis.ticks.length.y.right = unit(.5, "cm"), + axis.text.x.bottom = element_text(margin = margin(t = .5, unit = "cm")), + axis.text.x.top = element_text(margin = margin(b = .75, unit = "cm")) + ) expect_doppelganger("ticks_length", plot) }) From 62d8ca37a5eb76032c5a563bbbe4d7e26e3323da Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Oct 2018 14:39:13 +0200 Subject: [PATCH 04/12] Fix 456e7429 -- that commit was too aggressive --- R/guides-axis.r | 62 ++++++++++++++++++++++------------------------ R/theme-defaults.r | 10 ++++---- R/theme-elements.r | 8 +++--- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/R/guides-axis.r b/R/guides-axis.r index 10ad91cfd2..52eefea69d 100644 --- a/R/guides-axis.r +++ b/R/guides-axis.r @@ -82,57 +82,53 @@ guide_axis <- function(at, labels, position = "right", theme) { ticks <- switch(position, top = element_render(theme, "axis.ticks.x.top", - x = rep(at, each = 2), - y = rep(unit.c(zero, theme$axis.ticks.length.x.top), nticks), - id.lengths = rep(2, nticks) - ), + x = rep(at, each = 2), + y = rep(unit.c(zero, theme$axis.ticks.length.x.top), nticks), + id.lengths = rep(2, nticks)), bottom = element_render(theme, "axis.ticks.x.bottom", - x = rep(at, each = 2), - y = rep(unit.c(one - theme$axis.ticks.length.x.bottom, one), nticks), - id.lengths = rep(2, nticks) - ), + x = rep(at, each = 2), + y = rep(unit.c(one - theme$axis.ticks.length.x.bottom, one), nticks), + id.lengths = rep(2, nticks)), right = element_render(theme, "axis.ticks.y.right", - x = rep(unit.c(zero, theme$axis.ticks.length.y.right), nticks), - y = rep(at, each = 2), - id.lengths = rep(2, nticks) - ), + x = rep(unit.c(zero, theme$axis.ticks.length.y.right), nticks), + y = rep(at, each = 2), + id.lengths = rep(2, nticks)), left = element_render(theme, "axis.ticks.y.left", - x = rep(unit.c(one - theme$axis.ticks.length.y.left, one), nticks), - y = rep(at, each = 2), - id.lengths = rep(2, nticks) - ) + x = rep(unit.c(one - theme$axis.ticks.length.y.left, one), nticks), + y = rep(at, each = 2), + id.lengths = rep(2, nticks)) ) # Create the gtable for the ticks + labels gt <- switch(position, - top = gtable_col("axis", - grobs = list(labels, ticks), - width = one, + top = gtable_col("axis", + grobs = list(labels, ticks), + width = one, heights = unit.c(grobHeight(labels), theme$axis.ticks.length.x.top) ), bottom = gtable_col("axis", - grobs = list(ticks, labels), - width = one, + grobs = list(ticks, labels), + width = one, heights = unit.c(theme$axis.ticks.length.x.bottom, grobHeight(labels)) ), - right = gtable_row("axis", - grobs = list(ticks, labels), - widths = unit.c(theme$axis.ticks.length.y.right, grobWidth(labels)), - height = one + right = gtable_row("axis", + grobs = list(ticks, labels), + widths = unit.c(theme$axis.ticks.length.y.right, grobWidth(labels)), + height = one ), - left = gtable_row("axis", - grobs = list(labels, ticks), - widths = unit.c(grobWidth(labels), theme$axis.ticks.length.y.left), - height = one + left = gtable_row("axis", + grobs = list(labels, ticks), + widths = unit.c(grobWidth(labels), theme$axis.ticks.length.y.left), + height = one ) ) # Viewport for justifying the axis grob justvp <- switch(position, - top = viewport(y = 0, just = "bottom", height = gtable_height(gt)), - bottom = viewport(y = 1, just = "top", height = gtable_height(gt)), - right = viewport(x = 0, just = "left", width = gtable_width(gt)), - left = viewport(x = 1, just = "right", width = gtable_width(gt)) + top = viewport(y = 0, just = "bottom", height = gtable_height(gt)), + bottom = viewport(y = 1, just = "top", height = gtable_height(gt)), + right = viewport(x = 0, just = "left", width = gtable_width(gt)), + left = viewport(x = 1, just = "right", width = gtable_width(gt)) ) absoluteGrob( diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 31ba8eedc0..12063060ec 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -138,10 +138,13 @@ theme_grey <- function(base_size = 11, base_family = "", axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1), axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line / 2), hjust = 0), axis.ticks = element_line(colour = "grey20"), - axis.ticks.length = unit(half_line / 2, "pt"), + axis.ticks.length = unit(half_line / 2, "pt"), axis.ticks.length.x = NULL, axis.ticks.length.x.top = NULL, axis.ticks.length.x.bottom = NULL, + axis.ticks.length.y = NULL, + axis.ticks.length.y.left = NULL, + axis.ticks.length.y.right = NULL, axis.title.x = element_text( margin = margin(t = half_line / 2), vjust = 1 @@ -155,9 +158,6 @@ theme_grey <- function(base_size = 11, base_family = "", margin = margin(r = half_line / 2), vjust = 1 ), - axis.ticks.length.y = NULL, - axis.ticks.length.y.left = NULL, - axis.ticks.length.y.right = NULL, axis.title.y.right = element_text( angle = -90, margin = margin(l = half_line / 2), @@ -533,7 +533,7 @@ theme_test <- function(base_size = 11, base_family = "", axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1), axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line / 2), hjust = 0), axis.ticks = element_line(colour = "grey20"), - axis.ticks.length = unit(half_line / 2, "pt"), + axis.ticks.length = unit(half_line / 2, "pt"), axis.ticks.length.x = NULL, axis.ticks.length.x.top = NULL, axis.ticks.length.x.bottom = NULL, diff --git a/R/theme-elements.r b/R/theme-elements.r index 9804827a76..0b74e280db 100644 --- a/R/theme-elements.r +++ b/R/theme-elements.r @@ -285,15 +285,15 @@ el_def <- function(class = NULL, inherit = NULL, description = NULL) { axis.text.y = el_def("element_text", "axis.text"), axis.text.y.left = el_def("element_text", "axis.text.y"), axis.text.y.right = el_def("element_text", "axis.text.y"), - axis.ticks.length = el_def("unit"), + axis.ticks.length = el_def("unit"), axis.ticks.length.x = el_def("unit", "axis.ticks.length"), axis.ticks.length.x.top = el_def("unit", "axis.ticks.length.x"), axis.ticks.length.x.bottom = el_def("unit", "axis.ticks.length.x"), - axis.ticks.x = el_def("element_line", "axis.ticks"), - axis.ticks.x.top = el_def("element_line", "axis.ticks.x"), - axis.ticks.length.y = el_def("unit", "axis.ticks.length"), + axis.ticks.length.y = el_def("unit", "axis.ticks.length"), axis.ticks.length.y.left = el_def("unit", "axis.ticks.length.y"), axis.ticks.length.y.right = el_def("unit", "axis.ticks.length.y"), + axis.ticks.x = el_def("element_line", "axis.ticks"), + axis.ticks.x.top = el_def("element_line", "axis.ticks.x"), axis.ticks.x.bottom = el_def("element_line", "axis.ticks.x"), axis.ticks.y = el_def("element_line", "axis.ticks"), axis.ticks.y.left = el_def("element_line", "axis.ticks.y"), From 296d4dd1cd6f8d8515d6b46eb41a7a6d76c1b3e0 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Oct 2018 14:41:13 +0200 Subject: [PATCH 05/12] NEWS: Update issue reference --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 9f297b74c7..41ac3e34ac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -107,7 +107,7 @@ This is a minor release and breaking changes have been kept to a minimum. End us * New theme elements allowing different ticks lengths for each axis. For instance, this can be used to have inwards ticks on the x-axis (`axis.ticks.length.x`) and and outwards ticks on the - y-axis (`axis.ticks.length.y`). (@pank, #1319) + y-axis (`axis.ticks.length.y`). (@pank, #2935) # ggplot2 3.0.0 From 65b4b131a266f110fddde06368528b81406e8c7a Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Oct 2018 15:42:13 +0200 Subject: [PATCH 06/12] Remove unintended changes to Rd files --- man/facet_wrap.Rd | 2 +- man/scale_brewer.Rd | 8 ++++---- man/scale_gradient.Rd | 2 +- man/scale_grey.Rd | 4 ++-- man/scale_viridis.Rd | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/man/facet_wrap.Rd b/man/facet_wrap.Rd index 63776fa8e9..4621dfe47b 100644 --- a/man/facet_wrap.Rd +++ b/man/facet_wrap.Rd @@ -16,7 +16,7 @@ The variables can be named (the names are passed to \code{labeller}). For compatibility with the classic interface, can also be a formula or character vector. Use either a one sided formula, `~a \itemize{ -\item b\code{, or a character vector, }c("a", "b")`. +\item b\code{, or a character vector,}c("a", "b")`. }} \item{nrow, ncol}{Number of rows and columns.} diff --git a/man/scale_brewer.Rd b/man/scale_brewer.Rd index b12923bdc0..feb4299834 100644 --- a/man/scale_brewer.Rd +++ b/man/scale_brewer.Rd @@ -33,9 +33,9 @@ limits, breaks, labels and so forth.} \item{palette}{If a string, will use that named palette. If a number, will index into the list of palettes of appropriate \code{type}} -\item{direction}{Sets the order of colors in the scale. If 1, the default, -colors are as output by \code{\link[RColorBrewer]{brewer.pal}}. If -1, the -order of colors is reversed.} +\item{direction}{Sets the order of colours in the scale. If 1, the default, +colours are as output by \code{\link[RColorBrewer:brewer.pal]{RColorBrewer::brewer.pal()}}. If -1, the +order of colours is reversed.} \item{aesthetics}{Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with. This can be useful, for @@ -44,7 +44,7 @@ same time, via \code{aesthetics = c("colour", "fill")}.} \item{values}{if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the -\code{colours} vector. See \code{\link{rescale}} for a convience function +\code{colours} vector. See \code{\link[=rescale]{rescale()}} for a convenience function to map an arbitrary range to between 0 and 1.} \item{space}{colour space in which to calculate gradient. Must be "Lab" - diff --git a/man/scale_gradient.Rd b/man/scale_gradient.Rd index f41cb2b496..31cca12add 100644 --- a/man/scale_gradient.Rd +++ b/man/scale_gradient.Rd @@ -130,7 +130,7 @@ Defaults to 0.} \item{values}{if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the -\code{colours} vector. See \code{\link{rescale}} for a convience function +\code{colours} vector. See \code{\link[=rescale]{rescale()}} for a convenience function to map an arbitrary range to between 0 and 1.} } \description{ diff --git a/man/scale_grey.Rd b/man/scale_grey.Rd index b2b2d55a22..cc75334ada 100644 --- a/man/scale_grey.Rd +++ b/man/scale_grey.Rd @@ -66,9 +66,9 @@ scales, "top" or "bottom" for horizontal scales} \item{super}{The super class to use for the constructed scale} }} -\item{start}{gray value at low end of palette} +\item{start}{grey value at low end of palette} -\item{end}{gray value at high end of palette} +\item{end}{grey value at high end of palette} \item{na.value}{Colour to use for missing values} diff --git a/man/scale_viridis.Rd b/man/scale_viridis.Rd index 1043472c27..621aa8c6f3 100644 --- a/man/scale_viridis.Rd +++ b/man/scale_viridis.Rd @@ -50,7 +50,7 @@ same time, via \code{aesthetics = c("colour", "fill")}.} \item{values}{if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the -\code{colours} vector. See \code{\link{rescale}} for a convience function +\code{colours} vector. See \code{\link[=rescale]{rescale()}} for a convenience function to map an arbitrary range to between 0 and 1.} \item{space}{colour space in which to calculate gradient. Must be "Lab" - From 107ee4ac6052d7fb5a6a1cc668efd652c826f5fa Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Oct 2018 15:47:09 +0200 Subject: [PATCH 07/12] theme: New example only uses one unit --- R/theme.r | 2 +- man/theme.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/theme.r b/R/theme.r index 80c1f4f193..40d74ee4bb 100644 --- a/R/theme.r +++ b/R/theme.r @@ -199,7 +199,7 @@ #' p1 + theme( #' axis.ticks.length.y = unit(.25, "cm"), #' axis.ticks.length.x = unit(-.25, "cm"), -#' axis.text.x=element_text(margin=margin(t=8)) +#' axis.text.x=element_text(margin=margin(t=.3, unit="cm")) #' ) #' p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) #' diff --git a/man/theme.Rd b/man/theme.Rd index 626c852985..2591925f4a 100644 --- a/man/theme.Rd +++ b/man/theme.Rd @@ -257,7 +257,7 @@ p1 + theme(axis.ticks = element_line(size = 2)) p1 + theme( axis.ticks.length.y = unit(.25, "cm"), axis.ticks.length.x = unit(-.25, "cm"), - axis.text.x=element_text(margin=margin(t=8)) + axis.text.x=element_text(margin=margin(t=.3, unit="cm")) ) p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) From efc0eb3a58ee2ff28e543c7d4bca36ebd29f7219 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Oct 2018 16:42:01 +0200 Subject: [PATCH 08/12] theme-default: Update theme_void --- R/theme-defaults.r | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 12063060ec..876b5787e0 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -465,6 +465,12 @@ theme_void <- function(base_size = 11, base_family = "", axis.text = element_blank(), axis.title = element_blank(), axis.ticks.length = unit(0, "pt"), + axis.ticks.length.x = NULL, + axis.ticks.length.x.top = NULL, + axis.ticks.length.x.bottom = NULL, + axis.ticks.length.y = NULL, + axis.ticks.length.y.left = NULL, + axis.ticks.length.y.right = NULL, legend.box = NULL, legend.key.size = unit(1.2, "lines"), legend.position = "right", From 50aa9d9591e62e3f6223795fb82b22e168f56c0f Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 12 Apr 2019 14:57:46 +0200 Subject: [PATCH 09/12] Fix language and style according to Claus Wilke's recommendations * NEWS.md: Fix typo. * R/theme.r: Fix style and add comments for examples. --- NEWS.md | 4 ++-- R/theme.r | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 41ac3e34ac..dff94be2c7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -106,8 +106,8 @@ This is a minor release and breaking changes have been kept to a minimum. End us * New theme elements allowing different ticks lengths for each axis. For instance, this can be used to have inwards ticks on the - x-axis (`axis.ticks.length.x`) and and outwards ticks on the - y-axis (`axis.ticks.length.y`). (@pank, #2935) + x-axis (`axis.ticks.length.x`) and outwards ticks on the y-axis + (`axis.ticks.length.y`). (@pank, #2935) # ggplot2 3.0.0 diff --git a/R/theme.r b/R/theme.r index 40d74ee4bb..41ed5c05dc 100644 --- a/R/theme.r +++ b/R/theme.r @@ -193,15 +193,20 @@ #' ) #' #' # Axes ---------------------------------------------------------------------- +#' # Change styles of axes texts and lines #' p1 + theme(axis.line = element_line(size = 3, colour = "grey80")) #' p1 + theme(axis.text = element_text(colour = "blue")) #' p1 + theme(axis.ticks = element_line(size = 2)) +#' +#' # Change the appearance of the y-axis title +#' p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) +#' +#' # Make ticks point outwards on y-axis and upwards on x-axis #' p1 + theme( -#' axis.ticks.length.y = unit(.25, "cm"), -#' axis.ticks.length.x = unit(-.25, "cm"), -#' axis.text.x=element_text(margin=margin(t=.3, unit="cm")) +#' axis.ticks.length.y = unit(.25, "cm"), +#' axis.ticks.length.x = unit(-.25, "cm"), +#' axis.text.x = element_text(margin = margin(t = .3, unit = "cm")) #' ) -#' p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) #' #' \donttest{ #' # Legend -------------------------------------------------------------------- From 26ed5297f2715a1eab7339364671a6774634fa9e Mon Sep 17 00:00:00 2001 From: Rasmus Date: Mon, 15 Apr 2019 16:04:49 +0200 Subject: [PATCH 10/12] An additional language improvement suggested by Claus Wilke --- R/theme.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/theme.r b/R/theme.r index 41ed5c05dc..16c57d3d64 100644 --- a/R/theme.r +++ b/R/theme.r @@ -201,7 +201,7 @@ #' # Change the appearance of the y-axis title #' p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) #' -#' # Make ticks point outwards on y-axis and upwards on x-axis +#' # Make ticks point outwards on y-axis and inwards on x-axis #' p1 + theme( #' axis.ticks.length.y = unit(.25, "cm"), #' axis.ticks.length.x = unit(-.25, "cm"), From 50f8ceedac79d4ed0c458531ad019031ab8f8bc3 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Tue, 16 Apr 2019 09:19:27 +0200 Subject: [PATCH 11/12] Fix the NEWS.md entry --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index dff94be2c7..8b0b434927 100644 --- a/NEWS.md +++ b/NEWS.md @@ -107,7 +107,7 @@ This is a minor release and breaking changes have been kept to a minimum. End us * New theme elements allowing different ticks lengths for each axis. For instance, this can be used to have inwards ticks on the x-axis (`axis.ticks.length.x`) and outwards ticks on the y-axis - (`axis.ticks.length.y`). (@pank, #2935) + (`axis.ticks.length.y`) (@pank, #2935). # ggplot2 3.0.0 From eb5b72a1dd2d7a297b38f4092c34b5b1af07690c Mon Sep 17 00:00:00 2001 From: Rasmus Date: Tue, 16 Apr 2019 14:30:55 +0200 Subject: [PATCH 12/12] Move the location of the NEWS.md entry. Also use longer lines to somewhat better match other entries. --- NEWS.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7643021549..deea3e6a7e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -121,6 +121,11 @@ core developer team. * `sec_axis()` now accepts functions as well as formulas (@yutannihilation, #3031). +* New theme elements allowing different ticks lengths for each axis. For instance, + this can be used to have inwards ticks on the x-axis (`axis.ticks.length.x`) and + outwards ticks on the y-axis (`axis.ticks.length.y`) (@pank, #2935). + + # ggplot2 3.1.0 ## Breaking changes @@ -230,11 +235,6 @@ This is a minor release and breaking changes have been kept to a minimum. End us `nlevel`, an alias for `scaled`, to better match the syntax of `stat_bin()` (@bjreisman, #2679). -* New theme elements allowing different ticks lengths for each - axis. For instance, this can be used to have inwards ticks on the - x-axis (`axis.ticks.length.x`) and outwards ticks on the y-axis - (`axis.ticks.length.y`) (@pank, #2935). - # ggplot2 3.0.0 ## Breaking changes