我在資料框中有 3 列,我想使用 geom_smooth() 從中創建可視化:
ggplot(my_data_frame)
aes(x = fin_enquete,
y = intentions,
colour = candidat)
geom_point(alpha = 1/6,
shape = "circle",
size = .5L)
geom_smooth(mapping = aes(y = erreur_inf),
size = .5L,
span = .42,
se = F)
geom_smooth(mapping = aes(y = erreur_sup),
size = .5L,
span = .42,
se = F)
geom_smooth(method = "loess",
size = 1.5L,
span = .42,
se = F)
labs(x = "Date de fin d'enquête",
y = "Pourcentage d'intentions de vote")
theme_minimal()
theme(text = element_text(family = "DIN Pro"))
coord_cartesian(expand = F)
easy_remove_legend()

uj5u.com熱心網友回復:
您可以使用lapply() smooth 來計算 df 值的范圍,例如 (5,11,13) 來計算平滑度并僅繪制se.
示例代碼:
library(ggplot2)
ggplot(data = mtcars,
mapping = aes(x = wt,
y = mpg))
geom_point(size = 2)
lapply(c(5,11, 13), function (i) {
geom_smooth(
data = ~ cbind(., facet_plots = i),
method = lm,
se=F,
formula = y ~ splines::bs(x, i)
)
})
#facet_wrap(vars(facet_plots))
geom_ribbon(
stat = "smooth",
method = "loess",
se = TRUE,
alpha = 0, # or, use fill = NA
colour = "black",
linetype = "dotted")
theme_minimal()
陰謀:

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/445457.html
