Skip to content

Commit e0efd7b

Browse files
authored
annotation_logticks() skips ticks it hasn't found (#5259)
* Make sure you have ticks before trying to plot them * Add NEWS bullet
1 parent 940658a commit e0efd7b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

NEWS.md

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

3+
* Fixed bug in `annotation_logticks()` when no suitable tick positions could
4+
be found (@teunbrand, #5248).
35
* To improve `width` calculation in bar plots with empty factor levels,
46
`resolution()` considers `mapped_discrete` values as having resolution 1
57
(@teunbrand, #5211)

R/annotation-logticks.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
159159
xticks$end = -xticks$end
160160

161161
# Make the grobs
162-
if (grepl("b", sides)) {
162+
if (grepl("b", sides) && nrow(xticks) > 0) {
163163
ticks$x_b <- with(data, segmentsGrob(
164164
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
165165
y0 = unit(xticks$start, "cm"), y1 = unit(xticks$end, "cm"),
166166
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
167167
))
168168
}
169-
if (grepl("t", sides)) {
169+
if (grepl("t", sides) && nrow(xticks) > 0) {
170170
ticks$x_t <- with(data, segmentsGrob(
171171
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
172172
y0 = unit(1, "npc") - unit(xticks$start, "cm"), y1 = unit(1, "npc") - unit(xticks$end, "cm"),
@@ -197,14 +197,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
197197
yticks$end = -yticks$end
198198

199199
# Make the grobs
200-
if (grepl("l", sides)) {
200+
if (grepl("l", sides) && nrow(yticks) > 0) {
201201
ticks$y_l <- with(data, segmentsGrob(
202202
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
203203
x0 = unit(yticks$start, "cm"), x1 = unit(yticks$end, "cm"),
204204
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
205205
))
206206
}
207-
if (grepl("r", sides)) {
207+
if (grepl("r", sides) && nrow(yticks) > 0) {
208208
ticks$y_r <- with(data, segmentsGrob(
209209
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
210210
x0 = unit(1, "npc") - unit(yticks$start, "cm"), x1 = unit(1, "npc") - unit(yticks$end, "cm"),

0 commit comments

Comments
 (0)