drawing - Draw regression line per row in R -


i have following data.

heirank1

     hei.id x2007 x2008 x2009 x2010 x2011 x2012 1        op  41.8 147.6  90.3  82.9 106.8  63.0 2        mo  20.0  20.8  21.1  20.9  12.6  20.6 3        sd  21.2  32.3  25.7  23.9  25.0  40.1 4        un  51.8  39.8  19.9  20.9  21.6  22.5 5        ws  18.0  19.9  15.3  13.6  15.7  15.2 6        bf  11.5  36.9  20.0  23.2  18.2  23.8 7        me  34.2  30.3  28.4  30.1  31.5  25.6 8        im   7.7  18.1  20.5  14.6  17.2  17.1 9        om  11.4  11.2  12.2  11.1  13.4  19.2 10       dc  14.3  28.7  20.1  17.0  22.3  16.2 11       oc  28.6  44.0  24.9  27.9  34.0  30.7 12       th   7.4  10.0   5.8   8.8   8.7   8.6 13       cc  12.1  11.0  12.2  12.1  14.9  15.0 14       mm  11.7  24.2  18.4  18.6  31.9  31.7 15       mc  19.0  13.7  17.0  20.4  20.5  12.1 16       sh  11.4  24.8  26.1  12.7  19.9  25.9 17       sb  13.0  22.8  15.9  17.6  17.2   9.6 18       sn  11.5  18.6  22.9  12.0  20.3  11.6 19       er  10.8  13.2  20.0  11.0  14.9  14.2 20       sl  44.9  21.6  21.3  26.5  17.0   8.0 

i try following commends draw regression line each heis.

year <- c(2007 ,   2008  ,  2009  ,  2010 ,   2011, 2012)  op <- as.numeric(heirank1[1,]) lm.r <- lm(op~year) plot(year, op) abline(lm.r) 

i want draw draw regression line each college in 1 graph , not how.can me.

here's approach ggplot2 graph uninterpretable many lines.

library(ggplot2);library(reshape2) mdat <- melt(heirank1, variable.name="year") mdat$year <- as.numeric(substring(mdat$year, 2)) ggplot(mdat, aes(year, value, colour=hei.id, group=hei.id)) +     geom_point() + stat_smooth(se = false, method="lm") 

enter image description here

faceting may better way got:

ggplot(mdat, aes(year, value, group=hei.id)) +     geom_point() + stat_smooth(se = false, method="lm") +     facet_wrap(~hei.id) 

enter image description here


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -