是否可以向gg图添加曲线?

时间:2020-02-12 11:41:38

标签: ggplot2 plot curve

我已根据以下代码创建了一个图形:

df6<-structure(list(distance_down = c(0, 10, 20, 30, 40, 50, 60, 70, 80), downwind = c(6, 0, -1, -2, -3, -3.5, -3.5, -4, -4)), class = "data.frame", row.names = c(NA, -9L))

使用ggplot2:

downwindplot<-ggplot(data=df6,aes(x=distance_down,y=downwind))+geom_line()+geom_point()+labs(title = "Relationship between distance from source downwind and lesions present",x="Distance from Source",y="Downwind")

我已经创建了这张图

现在,我希望在该图中附加一条曲线,该曲线是使用以下代码创建的:

curve2<-curve(log(a.power)-b.power*log(x))

我试图这样做以使其工作:

 downwindplot + stat_function(fun=function(curve2))

哪个返回了意外的错误“)”

我也尝试过:

downwindplot + stat_smooth(method = "nls", formula = log(a.exp)-b.exp*x)

哪个返回了“无效的公式”

我想知道是否可以在ggplot2中做到这一点。

0 个答案:

没有答案