1
我正在使用ggplot2准备一个图,我想添加一个基于加权最小二乘估计的趋势线。在ggplot2中添加加权最小平方趋势线
在基地的图形,这可以通过发送一个WLS模型做abline
:
mod0 <- lm(ds$dMNP~ds$MNP)
mod1 <- lm(ds$dMNP~ds$MNP, weights = ds$Asset)
symbols(ds$dMNP~ds$MNP, circles=ds$r, inches=0.35)
#abline(mod0)
abline(mod1)
在GGPLOT2我设定的参数weight
在geom_smooth
但没有任何变化:
ggplot(ds, aes(x=MNP, y=dMNP, size=Asset) +
geom_point(shape=21) +
geom_smooth(method = "lm", weight="Asset", color="black", show.legend = FALSE)
这给了我同样的阴谋作为
ggplot(ds, aes(x=MNP, y=dMNP, size=Asset) +
geom_point(shape=21) +
geom_smooth(method = "lm", color="black", show.legend = FALSE)
您可以将此调整为内置数据集以获得重现性吗? –
你可以在'aes'中放置'weight','geom_smooth'将使用它 –