2017-05-31 85 views
-3

如何在R和Department and Year分组中绘制此图,时间为x轴,计数为y轴?并有连接线和颜色相同的群体如何绘制R中的2个分组变量?

Department Year Counts Time 
1  CPD 2011  24 0 
2  CPD 2011  28 1 
3  CPD 2011  31 2 
4  APD 2012  20 0 
5  APD 2012  25 2 
6  APD 2012  21 3 
7  CPD 2012  30 2 
8  CPD 2012  26 3 
9  CPD 2012  11 5 

回答

0

你的意思是这样的......

library(ggplot2) 
df$depYr <- paste(df$Department,df$Year,sep="_") #set a combined dept_year variable 
ggplot(df,aes(x=Time,y=Counts,colour=depYr,group=depYr))+geom_line() 

enter image description here