# r - R：使用curveid绘制的多行线

``````  Time        Type   Material      Value1      Value2
1    1          A          X          34        123
1    3          A          X          44        164
1    1          B          X          56        234
1    2          B          X          23        145
1    3          B          X          45        343
1    1          A          Y          45        243

...
``````

#### 1 个答案:

``````tms=range(df[,"Time"])
ylims=range(df[,c("Value1","Value2")])
plot(NA,type="n",xlim=tms,ylim=ylims,xlab="Time",ylab="Val")
df=df[with(df,order(Material,Time)),]
mats=unique(df\$Material)
sapply(1:length(mats),function(ma){points(df[df\$Material==mats[ma],"Time"],
df[df\$Material==mats[ma],"Value1"],
col=ma,pch=15  )
})
df=df[with(df,order(Type,Time)),]
library(RColorBrewer)
coly<-brewer.pal(8,"Accent")[8:1]
typs=unique(df\$Type)
sapply(1:length(typs),function(ma){points(df[df\$Type==typs[ma],"Time"],
df[df\$Type==typs[ma],"Value2"],
col=coly[ma],pch=15 ma  )
})
legend("top",c(mats,typs),pch=c(rep(15,length(mats)),15 1:length(typs)),
col=c(palette()[1:length(mats)],coly[1:length(typs)]),horiz=T)
``````

0条回复