I want to output two plots in a grid using the same function but with different input for x
. I am using ggplot2
with stat_function
as per this post and I have combined the two plots as per this post and this post.
f01 <- function(x) {1 - abs(x)}
ggplot() +
stat_function(data = data.frame(x=c(-1, 1)), aes(x = x, color = "red"), fun = f01) +
stat_function(data = data.frame(x=c(-2, 2)), aes(x = x, color = "black"), fun = f01)
With the following outputs:
Plot:
Message:
`mapping` is not used by stat_function()`data` is not used by stat_function()`mapping` is not used by stat_function()`data` is not used by stat_function()
I don't understand why stat_function()
won't use neither of the arguments. I would expect to plot two graphs one with x
between -1:1
and the second with x between -2:2
. Furthermore it takes the colors as labels, which I also don't understand why. I must be missing something obvious.