Skip to content

Commit 1ab70de

Browse files
committed
Add a blank layer to empty plots
1 parent 9651df8 commit 1ab70de

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
ggplot2 1.0.1.9xxx
22
----------------------------------------------------------------
33

4+
* ggplot no longer throws an error if you your plot doesn't have any
5+
layers. Instead it automatically adds `geom_blank()` (#1246)
6+
47
* `geom_smooth()` is no longer so chatty. If you want to know what the deafult
58
smoothing method is, look it up in the documentation! (#1247)
69

R/geom-blank.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#' c + geom_abline(aes(intercept = a, slope = b), data = df)
2424
geom_blank <- function(mapping = NULL, data = NULL, stat = "identity",
2525
position = "identity", show.legend = NA,
26-
inherit.aes = FALSE, ...) {
26+
inherit.aes = TRUE, ...) {
2727
layer(
2828
data = data,
2929
mapping = mapping,

R/limits.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ limits.POSIXlt <- function(lims, var) {
128128
expand_limits <- function(...) {
129129
data <- data.frame(..., stringsAsFactors = FALSE)
130130

131-
geom_blank(aes_all(names(data)), data)
131+
geom_blank(aes_all(names(data)), data, inherit.aes = FALSE)
132132
}

R/plot-build.r

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#' @keywords internal
1313
#' @export
1414
ggplot_build <- function(plot) {
15-
if (length(plot$layers) == 0) stop("No layers in plot", call. = FALSE)
16-
1715
plot <- plot_clone(plot)
16+
if (length(plot$layers) == 0) {
17+
plot <- plot + geom_blank()
18+
}
19+
1820
layers <- plot$layers
1921
layer_data <- lapply(layers, function(y) y$data)
2022

man/geom_blank.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
\title{Blank, draws nothing.}
66
\usage{
77
geom_blank(mapping = NULL, data = NULL, stat = "identity",
8-
position = "identity", show.legend = NA, inherit.aes = FALSE, ...)
8+
position = "identity", show.legend = NA, inherit.aes = TRUE, ...)
99
}
1010
\arguments{
1111
\item{mapping}{The aesthetic mapping, usually constructed with

0 commit comments

Comments
 (0)