R ggplot2仅适用于ablines
我遵循的是来自 代码如下:R ggplot2仅适用于ablines,r,plot,ggplot2,R,Plot,Ggplot2,我遵循的是来自 代码如下: library(plyr) coefs <- ddply(mtcars, .(cyl), function(df) { m <- lm(mpg ~ wt, data=df) data.frame(a = coef(m)[1], b = coef(m)[2]) }) p <- ggplot(mtcars, aes(x = wt, y=mpg), . ~ cyl) + geom_point() p + geom_abline(data=coef
library(plyr)
coefs <- ddply(mtcars, .(cyl), function(df) {
m <- lm(mpg ~ wt, data=df)
data.frame(a = coef(m)[1], b = coef(m)[2])
})
p <- ggplot(mtcars, aes(x = wt, y=mpg), . ~ cyl) + geom_point()
p + geom_abline(data=coefs, aes(intercept=a, slope=b))
库(plyr)
coefs您可以使用geom_blank()
,它将计算限制(等),但您只需使用geom_abline
:
p + geom_blank() + geom_abline(data=coefs, aes(intercept=a, slope=b))
您可以使用geom_blank()
,它将计算限制(等),但您只需使用geom_blank
:
p + geom_blank() + geom_abline(data=coefs, aes(intercept=a, slope=b))