我想在单个图中绘制多个折线图,以便能够根据不同的时间段(time series analysis
)比较5种不同癌症的发生率。我试图绘制函数,但是无法绘制这样的图形,以便我可以比较,例如目标登记处发生肝癌和胰腺癌的趋势是否相似?以下是我的数据集的摘录:
Registry.Name Type.of.Cancer Time.Period Gender ASR..W.
1 Ecuador Liver 1988-1992 1 2.9
2 Ecuador Liver 1993-1997 1 3.6
3 Ecuador Liver 1998-2002 1 3.4
4 Ecuador Liver 2003-2007 1 4.8
5 Ecuador Liver 1988-1992 2 2.8
6 Ecuador Liver 1993-1997 2 3.5
7 Ecuador Liver 1998-2002 2 3.9
8 Ecuador Liver 2003-2007 2 3.7
9 Ecuador Pancreas 1988-1992 1 3.8
10 Ecuador Pancreas 1993-1997 1 3.9
11 Ecuador Pancreas 1998-2002 1 3.0
12 Ecuador Pancreas 2003-2007 1 3.1
13 Ecuador Pancreas 1988-1992 2 4.4
14 Ecuador Pancreas 1993-1997 2 3.6
15 Ecuador Pancreas 1998-2002 2 2.9
16 Ecuador Pancreas 2003-2007 2 3.7
17 Ecuador Stomach 1988-1992 1 32.2
18 Ecuador Stomach 1993-1997 1 26.5
19 Ecuador Stomach 1998-2002 1 21.8
20 Ecuador Stomach 2003-2007 1 23.7
21 Ecuador Stomach 1988-1992 2 19.5
22 Ecuador Stomach 1993-1997 2 17.6
23 Ecuador Stomach 1998-2002 2 13.8
24 Ecuador Stomach 2003-2007 2 15.0
25 Ecuador NHL 1988-1992 1 8.2
26 Ecuador NHL 1993-1997 1 9.6
27 Ecuador NHL 1998-2002 1 9.2
28 Ecuador NHL 2003-2007 1 11.7
29 Ecuador NHL 1988-1992 2 6.0
30 Ecuador NHL 1993-1997 2 7.7
31 Ecuador NHL 1998-2002 2 7.8
32 Ecuador NHL 2003-2007 2 9.5
33 China 1 Liver 1988-1992 1 28.2
34 China 1 Liver 1993-1997 1 23.3
35 China 1 Liver 1998-2002 1 25.9
36 China 1 Liver 2003-2007 1 21.7
37 China 1 Liver 1988-1992 2 9.8
38 China 1 Liver 1993-1997 2 9.0
39 China 1 Liver 1998-2002 2 8.3
40 China 1 Liver 2003-2007 2 7.1
我试过了:
plot(Datgraph$Registry.Name, Datgraph$Type.of.Cancer)
但它没有制作合理的图表。
答案 0 :(得分:0)
我希望这些有帮助
library(ggplot2)
library(Rmisc)
#converting intger column to categorical
can$Gender<-as.factor(can$Gender)
#plotting multiple graphs
p1<-ggplot(data = can[can$Type.of.Cancer=='Ecuador Stomach',],aes(x = Time.Period,y = ASR..W.,group=Gender,color=Gender))+geom_line()+geom_point()+ggtitle('Ecuador Stomach')
p2<-ggplot(data = can[can$Type.of.Cancer=='Ecuador Pancreas',],aes(x = Time.Period,y = ASR..W.,group=Gender,color=Gender))+geom_line()+geom_point()+ggtitle('Ecuador Pancreas')
p3<-ggplot(data = can[can$Type.of.Cancer=='Ecuador NHL',],aes(x = Time.Period,y = ASR..W.,group=Gender,color=Gender))+geom_line()+geom_point()+ggtitle('Ecuador NHL')
p4<-ggplot(data = can[can$Type.of.Cancer=='Ecuador Liver',],aes(x = Time.Period,y = ASR..W.,group=Gender,color=Gender))+geom_line()+geom_point()+ggtitle('Ecuador Liver')
p5<-ggplot(data = can[can$Type.of.Cancer=='China 1 Liver',],aes(x = Time.Period,y = ASR..W.,group=Gender,color=Gender))+geom_line()+geom_point()+ggtitle('China 1 Liver')
multiplot(p1, p2, p3, p4,p5, cols=2)