Skip to content

Commit f4c97e8

Browse files
committed
resolve conflicts with master
1 parent 6e6b95f commit f4c97e8

File tree

3 files changed

+131
-153
lines changed

3 files changed

+131
-153
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ggplot2 (development version)
22

3+
* `geom_abline()`, `geom_hline()`, and `geom_vline()` now issue
4+
more informative warnings when supplied with set aesthetics
5+
(i.e., `slope`, `intercept`, `yintercept`, and/or `xintercept`)
6+
and mapped aesthetics (i.e., `data` and/or `mapping`).
7+
38
# ggplot2 3.2.0
49

510
This is a minor release with an emphasis on internal changes to make ggplot2

R/guides-axis.r

Lines changed: 98 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,115 @@
1-
# Grob for axes
2-
#
3-
# @param position of ticks
4-
# @param labels at ticks
5-
# @param position of axis (top, bottom, left or right)
6-
# @param range of data values
7-
guide_axis <- function(at, labels, position = "right", theme) {
8-
line <- switch(position,
9-
top = element_render(theme, "axis.line.x.top", c(0, 1), c(0, 0), id.lengths = 2),
10-
bottom = element_render(theme, "axis.line.x.bottom", c(0, 1), c(1, 1), id.lengths = 2),
11-
right = element_render(theme, "axis.line.y.right", c(0, 0), c(0, 1), id.lengths = 2),
12-
left = element_render(theme, "axis.line.y.left", c(1, 1), c(0, 1), id.lengths = 2)
13-
)
14-
position <- match.arg(position, c("top", "bottom", "right", "left"))
15-
16-
zero <- unit(0, "npc")
17-
one <- unit(1, "npc")
18-
19-
if (length(at) == 0) {
20-
vertical <- position %in% c("left", "right")
21-
return(absoluteGrob(
22-
gList(line),
23-
width = if (vertical) zero else one,
24-
height = if (vertical) one else zero
25-
))
26-
}
271

28-
at <- unit(at, "native")
29-
30-
theme$axis.ticks.length.x.bottom <- theme$axis.ticks.length.x.bottom %||%
31-
theme$axis.ticks.length.x %||%
32-
theme$axis.ticks.length
33-
theme$axis.ticks.length.x.top <- theme$axis.ticks.length.x.top %||%
34-
theme$axis.ticks.length.x %||%
35-
theme$axis.ticks.length
36-
theme$axis.ticks.length.y.left <- theme$axis.ticks.length.y.left %||%
37-
theme$axis.ticks.length.y %||%
38-
theme$axis.ticks.length
39-
theme$axis.ticks.length.y.right <- theme$axis.ticks.length.y.right %||%
40-
theme$axis.ticks.length.y %||%
41-
theme$axis.ticks.length
42-
43-
label_render <- switch(position,
44-
top = "axis.text.x.top", bottom = "axis.text.x.bottom",
45-
left = "axis.text.y.left", right = "axis.text.y.right"
46-
)
2+
#' Grob for axes
3+
#'
4+
#' @param break_position position of ticks
5+
#' @param break_labels labels at ticks
6+
#' @param axis_position position of axis (top, bottom, left or right)
7+
#' @param theme A [theme()] object
8+
#'
9+
#' @noRd
10+
#'
11+
draw_axis <- function(break_positions, break_labels, axis_position, theme) {
4712

48-
label_x <- switch(position,
49-
top = ,
50-
bottom = at,
51-
right = theme$axis.ticks.length.y.right,
52-
left = one - theme$axis.ticks.length.y.left
53-
)
54-
label_y <- switch(position,
55-
top = theme$axis.ticks.length.x.top,
56-
bottom = one - theme$axis.ticks.length.x.bottom,
57-
right = ,
58-
left = at
13+
axis_position <- match.arg(axis_position, c("top", "bottom", "right", "left"))
14+
aesthetic <- if (axis_position %in% c("top", "bottom")) "x" else "y"
15+
16+
# resolve elements
17+
line_element_name <- paste0("axis.line.", aesthetic, ".", axis_position)
18+
tick_element_name <- paste0("axis.ticks.", aesthetic, ".", axis_position)
19+
tick_length_element_name <- paste0("axis.ticks.length.", aesthetic, ".", axis_position)
20+
label_element_name <- paste0("axis.text.", aesthetic, ".", axis_position)
21+
22+
line_element <- calc_element(line_element_name, theme)
23+
tick_element <- calc_element(tick_element_name, theme)
24+
tick_length <- calc_element(tick_length_element_name, theme)
25+
label_element <- calc_element(label_element_name, theme)
26+
27+
# conditionally set parameters that depend on axis orientation
28+
is_vertical <- axis_position %in% c("left", "right")
29+
30+
position_dim <- if (is_vertical) "y" else "x"
31+
non_position_dim <- if (is_vertical) "x" else "y"
32+
position_size <- if (is_vertical) "height" else "width"
33+
non_position_size <- if (is_vertical) "width" else "height"
34+
label_margin_name <- if (is_vertical) "margin_x" else "margin_y"
35+
gtable_element <- if (is_vertical) gtable_row else gtable_col
36+
measure_gtable <- if (is_vertical) gtable_width else gtable_height
37+
measure_labels <- if (is_vertical) grobWidth else grobHeight
38+
39+
# conditionally set parameters that depend on which side of the panel
40+
# the axis is on
41+
is_second <- axis_position %in% c("right", "top")
42+
43+
tick_direction <- if (is_second) 1 else -1
44+
non_position_panel <- if (is_second) unit(0, "npc") else unit(1, "npc")
45+
tick_coordinate_order <- if (is_second) c(2, 1) else c(1, 2)
46+
47+
# conditionally set the gtable ordering
48+
labels_first_gtable <- axis_position %in% c("left", "top") # refers to position in gtable
49+
50+
table_order <- if (labels_first_gtable) c("labels", "ticks") else c("ticks", "labels")
51+
52+
# set common parameters
53+
n_breaks <- length(break_positions)
54+
opposite_positions <- c("top" = "bottom", "bottom" = "top", "right" = "left", "left" = "right")
55+
axis_position_opposite <- unname(opposite_positions[axis_position])
56+
57+
# draw elements
58+
line_grob <- exec(
59+
element_grob, line_element,
60+
!!position_dim := unit(c(0, 1), "npc"),
61+
!!non_position_dim := unit.c(non_position_panel, non_position_panel)
5962
)
6063

61-
if (is.list(labels)) {
62-
if (any(sapply(labels, is.language))) {
63-
labels <- do.call(expression, labels)
64-
} else {
65-
labels <- unlist(labels)
66-
}
64+
if (n_breaks == 0) {
65+
return(
66+
absoluteGrob(
67+
gList(line_grob),
68+
width = grobWidth(line_grob),
69+
height = grobHeight(line_grob)
70+
)
71+
)
6772
}
6873

69-
labels <- switch(position,
70-
top = ,
71-
bottom = element_render(theme, label_render, labels, x = label_x, margin_y = TRUE),
72-
right = ,
73-
left = element_render(theme, label_render, labels, y = label_y, margin_x = TRUE))
74-
75-
76-
77-
nticks <- length(at)
78-
79-
ticks <- switch(position,
80-
top = element_render(theme, "axis.ticks.x.top",
81-
x = rep(at, each = 2),
82-
y = rep(unit.c(zero, theme$axis.ticks.length.x.top), nticks),
83-
id.lengths = rep(2, nticks)),
84-
bottom = element_render(theme, "axis.ticks.x.bottom",
85-
x = rep(at, each = 2),
86-
y = rep(unit.c(one - theme$axis.ticks.length.x.bottom, one), nticks),
87-
id.lengths = rep(2, nticks)),
88-
right = element_render(theme, "axis.ticks.y.right",
89-
x = rep(unit.c(zero, theme$axis.ticks.length.y.right), nticks),
90-
y = rep(at, each = 2),
91-
id.lengths = rep(2, nticks)),
92-
left = element_render(theme, "axis.ticks.y.left",
93-
x = rep(unit.c(one - theme$axis.ticks.length.y.left, one), nticks),
94-
y = rep(at, each = 2),
95-
id.lengths = rep(2, nticks))
74+
labels_grob <- exec(
75+
element_grob, label_element,
76+
!!position_dim := unit(break_positions, "native"),
77+
!!label_margin_name := TRUE,
78+
label = break_labels
9679
)
9780

98-
# Create the gtable for the ticks + labels
99-
gt <- switch(position,
100-
top = gtable_col("axis",
101-
grobs = list(labels, ticks),
102-
width = one,
103-
heights = unit.c(grobHeight(labels), theme$axis.ticks.length.x.top)
104-
),
105-
bottom = gtable_col("axis",
106-
grobs = list(ticks, labels),
107-
width = one,
108-
heights = unit.c(theme$axis.ticks.length.x.bottom, grobHeight(labels))
81+
ticks_grob <- exec(
82+
element_grob, tick_element,
83+
!!position_dim := rep(unit(break_positions, "native"), each = 2),
84+
!!non_position_dim := rep(
85+
unit.c(non_position_panel + (tick_direction * tick_length), non_position_panel)[tick_coordinate_order],
86+
times = n_breaks
10987
),
110-
right = gtable_row("axis",
111-
grobs = list(ticks, labels),
112-
widths = unit.c(theme$axis.ticks.length.y.right, grobWidth(labels)),
113-
height = one
114-
),
115-
left = gtable_row("axis",
116-
grobs = list(labels, ticks),
117-
widths = unit.c(grobWidth(labels), theme$axis.ticks.length.y.left),
118-
height = one
119-
)
88+
id.lengths = rep(2, times = n_breaks)
89+
)
90+
91+
# create gtable
92+
table_order_int <- match(table_order, c("labels", "ticks"))
93+
non_position_sizes <- paste0(non_position_size, "s")
94+
95+
gt <- exec(
96+
gtable_element,
97+
name = "axis",
98+
grobs = list(labels_grob, ticks_grob)[table_order_int],
99+
!!non_position_sizes := unit.c(measure_labels(labels_grob), tick_length)[table_order_int],
100+
!!position_size := unit(1, "npc")
120101
)
121102

122-
# Viewport for justifying the axis grob
123-
justvp <- switch(position,
124-
top = viewport(y = 0, just = "bottom", height = gtable_height(gt)),
125-
bottom = viewport(y = 1, just = "top", height = gtable_height(gt)),
126-
right = viewport(x = 0, just = "left", width = gtable_width(gt)),
127-
left = viewport(x = 1, just = "right", width = gtable_width(gt))
103+
# create viewport
104+
justvp <- exec(
105+
viewport,
106+
!!non_position_dim := non_position_panel,
107+
!!non_position_size := measure_gtable(gt),
108+
just = axis_position_opposite
128109
)
129110

130111
absoluteGrob(
131-
gList(line, gt),
112+
gList(line_grob, gt),
132113
width = gtable_width(gt),
133114
height = gtable_height(gt),
134115
vp = justvp

_pkgdown.yml

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -217,39 +217,31 @@ reference:
217217
- map_data
218218

219219
navbar:
220-
title: ~
221-
type: default
222-
left:
223-
- text: Reference
224-
href: reference/index.html
225-
- text: Articles
226-
menu:
227-
- text: Aesthetic specifications
228-
href: articles/ggplot2-specs.html
229-
- text: Extending ggplot2
230-
href: articles/extending-ggplot2.html
231-
- text: News
232-
menu:
233-
- text: "Release notes"
234-
- text: "Version 3.2.0"
235-
href: https://www.tidyverse.org/articles/2019/06/ggplot2-3-2-0/
236-
- text: "Version 3.1.0"
237-
href: https://www.tidyverse.org/articles/2018/10/ggplot2-3-1-0/
238-
- text: "Version 3.0.0"
239-
href: https://www.tidyverse.org/articles/2018/07/ggplot2-3-0-0/
240-
- text: "Version 2.2.0"
241-
href: https://blog.rstudio.com/2016/11/14/ggplot2-2-2-0/
242-
- text: "Version 2.1.0"
243-
href: https://blog.rstudio.com/2016/03/03/ggplot2-2-1-0/
244-
- text: "Version 2.0.0"
245-
href: https://blog.rstudio.com/2015/12/21/ggplot2-2-0-0/
246-
- text: "Version 1.0.0"
247-
href: https://blog.rstudio.com/2015/01/09/ggplot2-updates/
248-
- text: "------------------"
249-
- text: "Change log"
250-
href: news/index.html
251-
- text: Extensions
252-
href: http://www.ggplot2-exts.org/gallery/
253-
right:
254-
- icon: fa-github fa-lg
255-
href: https://github.com/tidyverse/ggplot2
220+
structure:
221+
right: [extensions, github]
222+
components:
223+
home: ~
224+
news:
225+
text: News
226+
menu:
227+
- text: "Release notes"
228+
- text: "Version 3.2.0"
229+
href: https://www.tidyverse.org/articles/2019/06/ggplot2-3-2-0/
230+
- text: "Version 3.1.0"
231+
href: https://www.tidyverse.org/articles/2018/10/ggplot2-3-1-0/
232+
- text: "Version 3.0.0"
233+
href: https://www.tidyverse.org/articles/2018/07/ggplot2-3-0-0/
234+
- text: "Version 2.2.0"
235+
href: https://blog.rstudio.com/2016/11/14/ggplot2-2-2-0/
236+
- text: "Version 2.1.0"
237+
href: https://blog.rstudio.com/2016/03/03/ggplot2-2-1-0/
238+
- text: "Version 2.0.0"
239+
href: https://blog.rstudio.com/2015/12/21/ggplot2-2-0-0/
240+
- text: "Version 1.0.0"
241+
href: https://blog.rstudio.com/2015/01/09/ggplot2-updates/
242+
- text: "------------------"
243+
- text: "Change log"
244+
href: news/index.html
245+
extensions:
246+
text: Extensions
247+
href: http://www.ggplot2-exts.org/gallery/

0 commit comments

Comments
 (0)