Skip to content

Commit b029aa5

Browse files
authored
Check for range == NULL - happens if no data has been added to plot (#4682)
1 parent bd50a55 commit b029aa5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

NEWS.md

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

3+
* Fixed a bug throwing errors when trying to render an empty plot with secondary
4+
axes (@thomasp85, #4509)
5+
36
* Axes are now added correctly in `facet_wrap()` when `as.table = FALSE`
47
(@thomasp85, #4553)
58

R/axis-secondary.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
174174

175175
mono_test = function(self, scale){
176176
range <- scale$range$range
177+
178+
# Check if plot is empty
179+
if (is.null(range)) {
180+
return()
181+
}
182+
177183
along_range <- seq(range[1], range[2], length.out = self$detail)
178184
old_range <- scale$trans$inverse(along_range)
179185

0 commit comments

Comments
 (0)