Plotting multiple lines on same graph

Hi, I have a dataset showing gene expression of 25 genes. I wanted to show their expression patterns in comparison with one another (so on the same graph- although if someone has a better idea, please say).

I feel like I've gone about it in the worst way. Any help would be greatly appreciated. I am a newbie.

Data:

 Gene_ID         Name
1  KfGene001686-RA KgGene003950
2  KfGene003305-RA KgGene005761
3  KfGene013436-RA KgGene007054
4  KfGene010817-RA KgGene008773
5  KfGene021651-RA KgGene009113
6  KfGene017462-RA KgGene009699
7  KfGene023407-RA KgGene013521
8  KfGene020112-RA KgGene014989
9  KfGene047087-RA KgGene016113
10 KfGene021800-RA KgGene016131
11 KfGene027372-RA KgGene019586
12 KfGene010608-RA KgGene021134
13 KfGene009235-RA KgGene022206
14 KfGene038923-RA KgGene022959
15 KfGene038671-RA KgGene023146
16 KfGene042277-RA KgGene025874
17 KfGene046061-RA KgGene028203
18 KfGene017802-RA KgGene029754
19 KfGene044330-RA KgGene031775
20 KfGene049262-RA KgGene032770
21 KfGene051908-RA KgGene036270
22 KfGene006149-RA KgGene038284
23 KfGene007051-RA KgGene039081
24 KfGene007231-RA KgGene039169
25 KfGene007581-RA KgGene039437
                                                                                                      Description     LP1.2.L     LP1.6.L
1      "Similar to AGPS1 Glucose-1-phosphate adenylyltransferase large subunit 1 (Fragment) (Solanum tuberosum)"    0.4264431  0.52143121
2                                           "Similar to RPT2 Root phototropism protein 2 (Arabidopsis thaliana)"    0.4122265  0.06219286
3                                          "Similar to OFP2 Transcription repressor OFP2 (Arabidopsis thaliana)"   14.6008091  7.43314649
4                                           "Similar to TT12 Protein TRANSPARENT TESTA 12 (Arabidopsis thaliana)"   6.1392649  4.39425790
5                                   "Similar to AGT1 Serine--glyoxylate aminotransferase (Arabidopsis thaliana)"   17.2920840  9.19213274
6                                      "Similar to MBR1 E3 ubiquitin-protein ligase MBR1 (Arabidopsis thaliana)"  145.1126882 55.77949721
7                              "Similar to Os01g0794400 Probable nucleoredoxin 2 (Oryza sativa subsp. japonica)"   10.2413639  3.75089988
8                                                       "Similar to NADP-dependent malic enzyme (Vitis vinifera)"   6.8751455  4.48627072
9                                              "Similar to FAF1 Protein FANTASTIC FOUR 1 (Arabidopsis thaliana)"   84.0142386 10.89528380
10                                           "Similar to PSK6 Putative phytosulfokines 6 (Arabidopsis thaliana)"    4.2818285  4.30661445
11                                        "Similar to BBX32 B-box zinc finger protein 32 (Arabidopsis thaliana)"  183.7225775 12.61997616
12                                             "Similar to HAB1 Protein phosphatase 2C 16 (Arabidopsis thaliana)"   4.0473340  3.06663315
13                                                                "Similar to SS Sucrose synthase (Glycine max)"   23.1440493  8.32848959
14                                  "Similar to NUDT18 Nudix hydrolase 18, mitochondrial (Arabidopsis thaliana)"    8.6286346  4.01706307
15                       "Similar to ogdh 2-oxoglutarate dehydrogenase, mitochondrial (Dictyostelium discoideum)"   2.3051120  1.29359867
16                                                               "Similar to lip Lipase (Staphylococcus hyicus)"   62.1337068  3.64342613
17                              "Similar to At3g62260 Probable protein phosphatase 2C 49 (Arabidopsis thaliana)"   20.9940935 22.67153910
18                                            "Similar to HEMH Ferrochelatase-2, chloroplastic (Cucumis sativus)"   2.2201068  0.85731305
19      "Similar to Os02g0814900 Nicotinamide mononucleotide adenylyltransferase (Oryza sativa subsp. japonica)"   25.4562517 24.63512532
20                            "Similar to PPCK2 Phosphoenolpyruvate carboxylase kinase 2 (Arabidopsis thaliana)"    8.6620994 10.51275726
21  "Similar to PDK [Pyruvate dehydrogenase (acetyl-transferring)] kinase, mitochondrial (Arabidopsis thaliana)"    8.9156566  9.26763727
22                                        "Similar to BBX19 B-box zinc finger protein 19 (Arabidopsis thaliana)"    0.6648074  0.48156551
23                  "Similar to PPD Pyruvate, phosphate dikinase, chloroplastic (Mesembryanthemum crystallinum)"    0.1533274  0.00000000
24                                              "Similar to BAM9 Inactive beta-amylase 9 (Arabidopsis thaliana)"  149.8861201 74.87488653
25                   "Similar to CIPK1 CBL-interacting serine/threonine-protein kinase 1 (Arabidopsis thaliana)"   30.6399281 18.11187192
     LP1.10.L    LP1.14.D    LP1.18.D    LP1.22.D    C3.total      LP6.2.L      LP6.6.L     LP6.10.L     LP6.14.D     LP6.18.D    LP6.22.D
1   0.2133601   0.8430212   0.7502430   0.6900248   3.4445234   16.4185549    0.9023816    5.0930956 3.533190e+01   94.5372414   65.357835
2   0.0000000   0.2314601   0.2112554   0.1759484   1.0930833    1.0715797    0.4990551    0.4400818 9.105903e+00   24.6161083   24.558166
3   5.6703519   6.5570740   7.4213166   4.3975597  46.0802578  178.5743192   35.6985223   19.7006657 1.845690e+01   98.7268478   77.700972
4   0.9894706   5.8041184   7.7542889   5.5395039  30.6209045   38.0232572   11.8685914    2.7966816 9.887390e+00   85.9265634  141.972271
5   5.1030608   8.7821537  14.5675635  18.7647394  73.7017341   66.2603485   28.7889093   20.0530542 3.413571e+01  116.5450726  143.497169
6  30.4775395  45.5083921  52.0346459  71.7194843 400.6322472 1683.1774372  116.3847484   16.9971875 1.636875e+01  480.4353430 1042.550910
7   3.2513178   6.0309224  10.1626182  16.5206598  49.9577820   23.2564900    1.7205024    1.0586824 1.753363e+00   81.8385515  157.374504
8   4.6819403   9.3798388  12.5621347  13.6957459  51.6810758   32.4721477    8.6237208   11.5575678 7.698440e+01  118.1234515  122.325626
9   1.8752927  10.0032708  68.3018929 160.4874927 335.5774715   64.3020702    3.6529963    1.5641389 4.775783e+01  168.9211836  206.577497
10  3.5059520   6.5283774   7.3376091   4.5004226  30.4608041    5.3354962    5.4467062    5.5730065 3.141412e+01   67.3558547   52.908843
11  1.0746035   4.5619287  38.9165085 140.4976982 381.3932925  194.9908373    3.4146946    0.6486074 2.093917e+01  617.0983014 1036.509991
12  1.0671272   3.2177405   2.6652127   2.3904046  16.4544522   20.2769351   29.3950827   29.1545026 7.418605e+01   24.7283871   14.204890
13  8.4937532  11.4508221  23.9412844  30.8763938 106.2347924   19.7241650    3.7174692   10.6390067 2.184707e+02  493.6432298  487.438332
14  5.1304012   8.5577109  10.7234438   7.6325103  44.6897639   11.2776385    7.7268876   10.8347496 2.064168e+01   22.3713699   23.189719
15  1.4791686   2.1793645   2.2186922   1.8218322  11.2977682    2.7895203    2.1835422    1.4211416 4.954620e+00    7.2629566   10.143671
16  0.8155321   2.2422061  35.8281281 103.4660691 208.1290683  108.1908398    2.2502554    1.1120553 3.692218e+01  126.2838044  151.804979
17 20.1524642  30.9555731  26.8051761  26.7001286 148.2789746   44.9949385   28.6532563   24.9735806 3.579121e+01   37.0084131   48.436210
18  0.3688430   1.0930002   1.1246729   0.4485652   6.1125011   24.6796498    9.2094505    7.6399414 4.885953e+00    6.9089508    3.802639
19  9.4196101  37.4498270  66.1139217  31.7732991 194.8480349    3.8704895    1.2314163   11.0040589 2.905534e+01  102.1121242  142.733987
20 10.9093432   5.9254095   9.2788614   5.1360626  50.4245334    1.1282758    1.9296688   17.4202551 1.700417e+01   14.4149598   11.686084
21 10.6847013  11.6519048  10.4166068   7.4762513  58.4127582    7.8784681    4.6695005    7.6456648 1.184245e+01   13.1081761    8.948890
22  0.6567177   0.9066858   1.7365522   1.0848326   5.5311612    0.5245827    0.1556234    1.1510490 4.056261e+01   63.0262119   30.987811
23  0.0000000   0.0000000   0.0000000   0.0000000   0.1533274   14.5173036    4.8905799    0.8349723 4.146681e-02    0.2261183    0.000000
24 42.0272983 113.7850115 206.4108905 146.2144952 733.1987020 2610.5584795 1753.7868931 1509.1986928 2.113935e+03 2664.0804869 2652.695872
25 19.3076360  35.0680821  53.8591586 104.0636253 261.0503021   19.1370432   30.9437906   73.3727939 8.113122e+02 1525.3676310 1683.824735

Time <- c(2,6,10,14,18,22)
KF.1 <- c(KF$LP6.2.L[1],
KF$LP6.6.L[1],
KF$LP6.10.L[1],
KF$LP6.14.D[1],
KF$LP6.18.D[1],
KF$LP6.22.D[1])
KF.2 <- c(KF$LP6.2.L[2],
KF$LP6.6.L[2],
KF$LP6.10.L[2],
KF$LP6.14.D[2],
KF$LP6.18.D[2],
KF$LP6.22.D[2])
KF.3 <- c(KF$LP6.2.L[3],
KF$LP6.6.L[3],
KF$LP6.10.L[3],
KF$LP6.14.D[3],
KF$LP6.18.D[3],
KF$LP6.22.D[3])
KF.4 <- c(KF$LP6.2.L[4],
KF$LP6.6.L[4],
KF$LP6.10.L[4],
KF$LP6.14.D[4],
KF$LP6.18.D[4],
KF$LP6.22.D[4])
KF.5 <- c(KF$LP6.2.L[5],
KF$LP6.6.L[5],
KF$LP6.10.L[5],
KF$LP6.14.D[5],
KF$LP6.18.D[5],
KF$LP6.22.D[5])
KF.6 <- c(KF$LP6.2.L[6],
KF$LP6.6.L[6],
KF$LP6.10.L[6],
KF$LP6.14.D[6],
KF$LP6.18.D[6],
KF$LP6.22.D[6])
KF.7 <- c(KF$LP6.2.L[7],
KF$LP6.6.L[7],
KF$LP6.10.L[7],
KF$LP6.14.D[7],
KF$LP6.18.D[7],
KF$LP6.22.D[7])
KF.8 <- c(KF$LP6.2.L[8],
KF$LP6.6.L[8],
KF$LP6.10.L[8],
KF$LP6.14.D[8],
KF$LP6.18.D[8],
KF$LP6.22.D[8])
KF.9 <- c(KF$LP6.2.L[9],
KF$LP6.6.L[9],
KF$LP6.10.L[9],
KF$LP6.14.D[9],
KF$LP6.18.D[9],
KF$LP6.22.D[9])
KF.10 <- c(KF$LP6.2.L[10],
KF$LP6.6.L[10],
KF$LP6.10.L[10],
KF$LP6.14.D[10],
KF$LP6.18.D[10],
KF$LP6.22.D[10])
KF.11 <- c(KF$LP6.2.L[11],
KF$LP6.6.L[11],
KF$LP6.10.L[11],
KF$LP6.14.D[11],
KF$LP6.18.D[11],
KF$LP6.22.D[11]
KF.12 <- c(KF$LP6.2.L[12],
KF$LP6.6.L[12],
KF$LP6.10.L[12],
KF$LP6.14.D[12],
KF$LP6.18.D[12],
KF$LP6.22.D[12])
KF.13 <- c(KF$LP6.2.L[13],
KF$LP6.6.L[13],
KF$LP6.10.L[13],
KF$LP6.14.D[13],
KF$LP6.18.D[13],
KF$LP6.22.D[13])
KF.14 <- c(KF$LP6.2.L[14],
KF$LP6.6.L[14],
KF$LP6.10.L[14],
KF$LP6.14.D[14],
KF$LP6.18.D[14],
KF$LP6.22.D[14])
KF.15 <- c(KF$LP6.2.L[15],
KF$LP6.6.L[15],
KF$LP6.10.L[15],
KF$LP6.14.D[15],
KF$LP6.18.D[15],
KF$LP6.22.D[15])
KF.16 <- c(KF$LP6.2.L[16],
KF$LP6.6.L[16],
KF$LP6.10.L[16],
KF$LP6.14.D[16],
KF$LP6.18.D[16],
KF$LP6.22.D[16])
KF.17 <- c(KF$LP6.2.L[17],
KF$LP6.6.L[17],
KF$LP6.10.L[17],
KF$LP6.14.D[17],
KF$LP6.18.D[17],
KF$LP6.22.D[17])
KF.18 <- c(KF$LP6.2.L[18],
KF$LP6.6.L[18],
KF$LP6.10.L[18],
KF$LP6.14.D[18],
KF$LP6.18.D[18],
KF$LP6.22.D[18])
KF.19 <- c(KF$LP6.2.L[19],
KF$LP6.6.L[19],
KF$LP6.10.L[19],
KF$LP6.14.D[19],
KF$LP6.18.D[19],
KF$LP6.22.D[19])
KF.20 <- c(KF$LP6.2.L[20],
KF$LP6.6.L[20],
KF$LP6.10.L[20],
KF$LP6.14.D[20],
KF$LP6.18.D[20],
KF$LP6.22.D[20])
KF.21 <- c(KF$LP6.2.L[21],
KF$LP6.6.L[21],
KF$LP6.10.L[21],
KF$LP6.14.D[21],
KF$LP6.18.D[21],
KF$LP6.22.D[21])
KF.22 <- c(KF$LP6.2.L[22],
KF$LP6.6.L[22],
KF$LP6.10.L[22],
KF$LP6.14.D[22],
KF$LP6.18.D[22],
KF$LP6.22.D[22])
KF.23 <- c(KF$LP6.2.L[23],
KF$LP6.6.L[23],
KF$LP6.10.L[23],
KF$LP6.14.D[23],
KF$LP6.18.D[23],
KF$LP6.22.D[23])
KF.24 <- c(KF$LP6.2.L[24],
KF$LP6.6.L[24],
KF$LP6.10.L[24],
KF$LP6.14.D[24],
KF$LP6.18.D[24],
KF$LP6.22.D[24])
KF.25 <- c(KF$LP6.2.L[25],
KF$LP6.6.L[25],
KF$LP6.10.L[25],
KF$LP6.14.D[25],
KF$LP6.18.D[25],
KF$LP6.22.D[25])

#Combine vectors into a matrix to plot the gene expression####

GraphingMatrix<-cbind(Time, KF.1, KF.2, KF.3, KF.4, KF.5, KF.6, KF.7, KF.8, KF.9, KF.10,
KF.11, KF.12, KF.13, KF.14, KF.15, KF.16, KF.17, KF.18, KF.19,
KF.20, KF.21, KF.22, KF.23, KF.24, KF.25)

jpeg(paste("PPCK-like Expression", ".jpeg", sep="")) #name of jpeg file

#Set plot layout
layout(mat = matrix(c(1, 2),
nrow = 1,
ncol = 1),
heights = c(2, 2), # Heights of the two rows
widths = c(2)) # Widths of the two columns

#par(mfrow=c(2,1))
min_value = min(GraphingMatrix[,2:ncol(GraphingMatrix)])
max_value = max(GraphingMatrix[,2:ncol(GraphingMatrix)])

#plot1
print(plot(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.1'], type='b',
xlim=c(0, 25), ylim=c(min_value, max_value), main="PPCK-like Expression")),
col = "blue", xlab = "Time (h)", ylab = "Expression")),
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.2'], type='b', col='red')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.3'], type='b', col='turquoise4')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.4'], type='b', col='green')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.5'], type='b', col='yellow')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.6'], type='b', col='orange')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.7'], type='b', col='cyan')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.8'], type='b', col='dimgrey')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.9'], type='b', col='deeppink')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.10'], type='b', col='darkslategray')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.11'], type='b', col='goldenrod')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.12'], type='b', col='firebrick')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.13'], type='b', col='forestgreen')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.14'], type='b', col='hotpink')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.15'], type='b', col='lightblue')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.16'], type='b', col='lightsalmon')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.17'], type='b', col='magenta')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.18'], type='b', col='maroon')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.19'], type='b', col='olivedrab')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.20'], type='b', col='mediumorchid')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.21'], type='b', col='pink')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.22'], type='b', col='plum4')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.23'], type='b', col='royalblue')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.24'], type='b', col='sienna1')
lines(x=GraphingMatrix[,'Time'], y=GraphingMatrix[,'KF.25'], type='b', col='tomato4')
legend(x="topleft",
legend=c('AGPS1', 'RPT2', 'OFP2', 'TT12', 'AGT1', 'MBR1', 'Nucleoredoxin 2', 'NADP-ME', 'FAF1',
'PSK6', 'BBX32', 'HAB1', 'SS', 'NUDT18', 'ogdh', 'Lip', 'PP2C', 'HEMH', 'Nicotinamide',
'PPCK', 'PDK', 'BBX19', 'PPD', 'BAM9', 'CIPK1'),
col=c('blue', 'red', 'tuquoise4', 'green', 'yellow', 'orange', 'cyan','dimgrey',
'deeppink', 'darkslategray', 'goldenrod', 'firebrick', 'forestgreen', 'hotpink',
'lightblue', 'lightsalmon', 'magenta', 'maroon', 'olivedrab', 'mediumorchid',
'pink', 'plum4', 'royalblue', 'sienna1', 'tomato4'),
lty = 1, lwd = 2, cex=0.55)

Your data seems to be unusable.

I think you should have a look at FAQ: How to do a minimal reproducible example ( reprex ) for beginners
or just give us the original raw data which I assume is the data.frame KF.

A handy way to supply sample data is to use the dput() function. See ?dput. Usually if you have a very large data set then something like head(dput(myfile), 100) will likely supply enough data for us to work with but I am not sure here.

I would not go that far but one we know what your data looks like I suspect one of the resident gurus can help you do things in a better and easier way.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.