简体   繁体   中英

Plot multiple fits lines in base graphics in r

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

library(lme4)
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?

在此处输入图片说明

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM