是否可以定义函数将绘制在图中的边界ggplot2
前任
f <- ggplot(data.frame(x = c(0, 10)), aes(x))
test <- function(x) {x ^ 2 + x + 20}
f + stat_function(fun = test)
这是一种在区间内绘制test
函数的方法c(2, 5)
在stat_function
范围内设置 x 限制,并使用 geom_blank
获取与数据对应的 x 限制:
f + geom_blank() + stat_function(fun = test, xlim = c(2, 5))