Juanchi Juanchi - 1 year ago 91
R Question

Plot multiple fits lines in base graphics in r

I'm trying to plot multiple fitted lm lines in an only plot:

fits <- lmList(Sepal.Length ~ Petal.Width | Species, data=iris)
coefs <- data.frame(coef(fits)); names(coefs) = c("Int", "slopes")

Then I plot all the fits at once via ggplot:

ggplot(iris, aes(x = Petal.Width, y=Sepal.Length)) +
geom_point(shape=1,size = 0.5)+
geom_abline(aes(intercept= Int , slope=slopes), color='grey', data=coefs)

Can someone help me to do it in the base graphics way?

enter image description here

Answer Source
plot(Sepal.Length ~ Petal.Width, data = iris)
lapply(fits, abline)

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download