Is there a way of overlaying a mathematical function on top of data using 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 #?
In this case my data is generated using the function, but I want to understand how to use 'curve()' with ggplot. Thanks.