-5

I want to plot multiple line graphs in a single plot in order to be able to compare the occurrence of 5 different cancers based on different time periods (time series analysis). I tried to plot function but it is not possible to plot such that I can compare if e.g. the occurrence of liver cancer and pancreas cancer in the target registries have similar trends or not? Here is an excerpt of my data set:

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

I tried:

plot(Datgraph$Registry.Name, Datgraph$Type.of.Cancer)

but it does not make sensible graphs.

zx8754
  • 52,746
  • 12
  • 114
  • 209
A. Shams
  • 1
  • 1
  • I notice that my data set excerpts is not displayed correctly . So I wanted to attach the excel file but now it is not possible. Any idea on how to do so? – A. Shams Jun 07 '16 at 13:38
  • You can click on [edit link above](http://stackoverflow.com/posts/37680576/edit). – zx8754 Jun 07 '16 at 13:43
  • Welcome to Stack Overflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Jun 07 '16 at 13:44

1 Answers1

0

i hope these helps

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)
Sijo Jose
  • 41
  • 4