Skip to content

Commit 1ae28f5

Browse files
committed
Warn when contour generates no data.
Fixes #316
1 parent 008312c commit 1ae28f5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

R/plot-render.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ ggplot_gtable <- function(data) {
2222
theme <- plot_theme(plot)
2323

2424
build_grob <- function(layer, layer_data) {
25+
if (nrow(layer_data) == 0) return()
26+
2527
dlply(layer_data, "PANEL", function(df) {
2628
panel_i <- match(df$PANEL[1], panel$layout$PANEL)
2729
layer$make_grob(df, scales = panel$ranges[[panel_i]], cs = plot$coord)

R/stat-contour.r

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ StatContour <- proto(Stat, {
7272
cl <- contourLines(
7373
x = sort(unique(data$x)), y = sort(unique(data$y)), z = z,
7474
levels = breaks)
75-
if (length(cl) == 0) return(data.frame())
75+
if (length(cl) == 0) {
76+
warning("Not possible to generate contour data", call. = FALSE)
77+
return(data.frame())
78+
}
7679

7780
cl <- lapply(cl, as.data.frame)
7881
contour_df <- rbind.fill(cl)

0 commit comments

Comments
 (0)