Open jiyunson opened 1 year ago
Hi, as I continue to test out gf_function()
there seems to be some discrepancy between the way gf_function()
and geom_function()
work.
This ggplot2 syntax produces the graph below:
test_function <- function(X){ 60.3605 + 0.6665*X}
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(color = "steelblue") +
geom_function(fun = test_function, xlim = c(10,40))
I had expected this ggformula code to produce the same thing; but it doesn't:
test_function <- function(X){ 60.3605 + 0.6665*X}
gf_point(mpg ~ wt, data = mtcars, color = "steelblue") %>%
gf_function(test_function, xlim = c(10,40))
In my various tests of xlim
values (within the range of the data; outside the range of the data), gf_function
seems to be ignoring the xlim()
argument.
Sorry for the slow response. Pending some testing, I think I may have this fixed.
suppressPackageStartupMessages(library(ggformula))
test_function <- function(X){ 60.3605 + 0.6665*X}
gf_point(mpg ~ wt, data = mtcars, color = "steelblue") %>%
gf_function(test_function, xlim = c(10,40))
Created on 2023-08-30 with reprex v2.0.2
Randy, thanks!
Hi @rpruim! Thanks for working on this. Could you let me know when the fix will be available (e.g., via github)? I tried reinstalling ggformula
fro github (i.e., devtools::install_github("ProjectMOSAIC/ggformula")
) and the fix wasn't working yet...
Also is there a way to make gf_function()
only appear for one facet in a faceted plot? I might do this in ggplot2:
test_function <- function(X){ 60.3605 + 0.6665*X}
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(color = "steelblue") +
facet_wrap(~ vs) +
geom_function(data = filter(mtcars, vs == 1), fun = test_function, xlim = c(10,40))
I would assume this would be the ggformula version:
gf_point(mpg ~ wt, data = mtcars) %>%
gf_facet_wrap(~ vs) %>%
gf_function(test_function, data = filter(mtcars, vs == 1))
As always, just such a big fan of
ggformula
and all the development work you do! I've had several experiences where I'm thinking "it would be nice if there was..." and voila --ggformula
has already thought of it. Thanks!I've been playing more with
gf_function()
and there seems to be something odd about it when I'm just using vectors instead of data frames.If I leave the
xlim
argument out ofgf_function
, it won't depict the function.But if I put the
xlim
in, it will work as expected. Is there a way to getgf_function()
to work without having to setxlim
?If I use
gf_function()
on an x and y that is in a data frame (as in themtcars
example below), it works withoutxlim
.Thanks for considering!