我正在尝试使用以下代码进行简单绘制。
eta = c(0, 0.2, 0.4, 0.6, 0.8, 1)
R = c(0, 0.647058807, 0.864035125, 0.992063541, 0.996376783, 1)
p = as.data.frame(cbind(eta, R))
library(ggplot2)
ggplot(p) +
geom_point(aes(x = eta, y = R), size = 3) +
geom_smooth(aes(y=R, x=eta), method = "loess", se = FALSE)
我得到如下图:
geom_smooth函数可以接受参数来更改线宽或线型吗?有没有一种方法可以使拟合更好,以使曲线看起来像下面的曲线一样好的连续函数?
您可以更改拟合的span
使其或多或少平滑。您也可以使用size
更改线宽,并使用linetype
键入:
ggplot(p) +
geom_point(aes(x = eta, y = R), size = 3) +
geom_smooth(
aes(y=R, x=eta),
method = "loess",
se = FALSE,
span = 0.9,
linetype = "dashed",
size = 0.5)