I want to add a curve with the following equation to an x,y scatterplot: y<-(105+0.043(x^2-54x)). Is it possible within the plot() function? Also, if I use qplot instead (ggplot2) is there a way to draw this curve?
# data for scatterplot
x = rnorm(10, sd = 10)
y = (105 + 0.043 * (x^2 - 54 * x)) + rnorm(10, sd = 5)
Base plotting
plot(x, y)
curve(105 + 0.043 * (x^2 - 54 * x), add = T)
For ggplot, we need a data.frame
dat = data.frame(x = x, y = y)
ggplot(dat, aes(x , y)) +
geom_point() +
stat_function(fun = function(x) 105 + 0.043 * (x^2 - 54 * x))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With