有没有一种使用ggplot在数据上叠加数学函数的方法?
在这种情况下,我的数据是使用函数生成的,但我想了解如何在ggplot中使用
## add ggplot2
library(ggplot2)
# function
eq = function(x){x*x}
# Data
x = (1:50)
y = eq(x)
# Make plot object
p = qplot(
x, y,
xlab = "X-axis",
ylab = "Y-axis",
)
# Plot Equation
c = curve(eq)
# Combine data and function
p + c #?
在这种情况下,我的数据是使用函数生成的,但我想了解如何在ggplot中使用
curve()
。