r语言 - 定义区间的绘图函数



是否可以定义函数将绘制在图中的边界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))

最新更新