2017-05-31 82 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