This comes from a discussion with @clauswilke. The issue here is related to #2950 but somewhat different.
When a data frame is provided to geom_hline(), it is overwritten. The problem seems to be in the following code chunk:
|
# Act like an annotation |
|
if (!missing(yintercept)) { |
|
data <- new_data_frame(list(yintercept = yintercept)) |
|
mapping <- aes(yintercept = yintercept) |
|
show.legend <- FALSE |
|
} |
Here is a reprex to demonstrate this issue:
This works as expected
library(ggplot2)
library(tidyr)
d <- data.frame(c = c("a", "b"),
y = c(1, 3))
d %>% ggplot() +
geom_hline(data = d, aes(yintercept = y, color = c)) +
facet_wrap(~c)

This doesn't work as expected. The provided data frame is dropped, and colors aren't mapped.
d %>% ggplot() +
geom_hline(data = d, aes(color = c), yintercept = 1) +
facet_wrap(~c)

Created on 2019-01-19 by the reprex package (v0.2.1)
No warning is given when the original data frame is being overwritten.
This comes from a discussion with @clauswilke. The issue here is related to #2950 but somewhat different.
When a data frame is provided to
geom_hline(), it is overwritten. The problem seems to be in the following code chunk:ggplot2/R/geom-hline.r
Lines 12 to 17 in 3c3062d
Here is a reprex to demonstrate this issue:
This works as expected
This doesn't work as expected. The provided data frame is dropped, and colors aren't mapped.
Created on 2019-01-19 by the reprex package (v0.2.1)
No warning is given when the original data frame is being overwritten.