-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stat_function() doesn't work without dummy data #3983
Comments
We can work around this issue by adding at least one group explicitly. library(ggplot2)
# doesn't work
ggplot() + xlim(-5, 5) +
stat_function(fun = dnorm) # works
ggplot() + xlim(-5, 5) +
stat_function(aes(group = 1), fun = dnorm) Created on 2020-05-01 by the reprex package (v0.3.0) @thomasp85 Can you see a way to simulate this via |
The reason why Lines 271 to 278 in 49aca36
For the same reason, overriding compute_panel() won't do anything.
|
Never mind, I figured it out. PR #3984. library(ggplot2)
ggplot() + xlim(-5, 5) +
geom_function(fun = dnorm) ggplot() + xlim(-5, 5) +
geom_function(fun = dnorm) +
scale_y_log10() ggplot() +
geom_function(fun = dnorm, xlim = c(-5, 5)) ggplot() +
geom_function(fun = dnorm) Created on 2020-05-02 by the reprex package (v0.3.0) And everything else I've fixed previously still works. library(tidyverse)
data <- tibble(
x = 1:50,
y = x*x - 2*x + 500 + 200*rnorm(50),
a = sample(letters[1:3], 50, replace = TRUE)
)
ggplot(data, aes(x, y)) +
geom_point(aes(color = "data")) +
geom_function(aes(color = "function"), fun = ~.x*.x - 2*.x + 500) +
scale_y_log10() + scale_x_log10() ggplot(data, aes(x, y, color = a)) +
geom_point() +
geom_function(fun = ~.x*.x - 2*.x + 500) +
scale_y_log10() + facet_wrap(~a) Created on 2020-05-02 by the reprex package (v0.3.0) |
* make stat_function() work with empty input data. fixes #3983. * update news item, fix documentation, add unit tests * one more test
I would have expected the second and third example below to work, but it doesn't.
Created on 2020-05-01 by the reprex package (v0.3.0)
The problem seems to be that
stat_function()
doesn't return any data in the second and third case, or the data gets somehow deleted. It would be nice if we could solve this before the 3.3.1 release, I assume (hope!) it's a simple fix.Created on 2020-05-01 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: