[英]R: Add a curve,with my own equation, to an x,y scatterplot
我想在x,y散点图中添加具有以下等式的曲线:y < - (105 + 0.043(x ^ 2-54x))。 是否可以在plot()函数中使用? 另外,如果我使用qplot代替(ggplot2)有没有办法绘制这条曲线?
# data for scatterplot
x = rnorm(10, sd = 10)
y = (105 + 0.043 * (x^2 - 54 * x)) + rnorm(10, sd = 5)
基础绘图
plot(x, y)
curve(105 + 0.043 * (x^2 - 54 * x), add = T)
对于ggplot,我们需要一个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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.