使用for-loop绘制每个物种的情节?

时间:2014-01-06 00:18:40

标签: r for-loop plot regression

我有9种植物,我想要绘制一种关系。我一直在密谋,因为我需要单独为图表添加文字。我将9个图格式化为适合3x3网格中的一个页面。 但有没有办法用循环来做到这一点?并将9个图形格式化为3x3?如果可以,你还可以在每个情节中添加文字吗?

我的所有9个代码都是这样的,但这里是前2种 首先我按物种分类:

Acru<-carbon2[Species=="Acru",]    
Arte<-carbon2[Species=="Arte",]  

...

par(mfrow=c(3,3), cex=.3) 

plot(LogRecBio~LogPreBiomass,data=Acru,font.lab=2,font.main=2, font.sub=3, mgp=c(2.5,1,0), cex.lab=2, cex.main=1.5, axes=F,lwd=1.5, cex=2.5, ann=F)
box()
axis(1,at=c(-2,-1,0,1,2,3,4),font=2,cex.axis=3)
axis(2,at=c(-5,-4,-3,-2,-1,0,1,2),font=2,cex.axis=3)
text(2,-0.27, sprintf("a) Acer rubrum"),font=3,cex=2.5)
text(2.35,-0.6,sprintf("R²= 0.18"),cex=2.5)
fit.bio.acru1 <- lm(LogRecBio ~LogPreBiomass, data=Acru, subset=c(Site=="7"))
abline(fit.bio.acru1, lwd=2, col='red')
fit.bio.acru2 <- lm(LogRecBio ~LogPreBiomass, data=Acru,subset=c(Site=="8"))
abline(fit.bio.acru2, lwd=2, col='blue')
fit.bio.acru


plot(LogRecBio~LogPreBiomass,data=Arte,font.lab=2,font.main=2, font.sub=3, mgp=c(2.5,1,0), cex.lab=2, cex.main=1.5, cex.axis=1.2,axes=F,lwd=1.5, cex=2.2, ann=F)
box()
axis(1,at=c(-3,-2,-1,0,1.0,2,3),font=2,cex.axis=3)
axis(2,at=c(-4,-3,-2,-1,0,1,2),font=2,cex.axis=3)
text(2.05,0.97, sprintf("b) Arundinaria tecta"),font=3,cex= 2.5)
text(2.56,0.59,sprintf("R² = 0.04"),cex= 2.5)
fit.bio.arte <- lm(LogRecBio ~LogPreBiomass, data=Arte)
abline(fit.bio.arte, lwd=2, col='red')
fit.bio.arte

部分数据框carbon2:

structure(list(Treatment = c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L), Species = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L), .Label = c("Acru", "Arte", "Clal", "Euro", "Gafr", "Ilgl", 
"Lylu", "Oxar", "Pepu"), class = "factor"), Tag = c(64L, 248L, 
249L, 250L, 251L, 252L, 253L, 315L, 316L, 318L, 931L, 932L, 933L, 
934L, 935L, 936L, 3L, 4L, 5L, 6L, 917L, 918L, 919L, 920L, 921L, 
923L, 924L, 995L, 996L, 997L, 208L, 209L, 210L, 211L, 212L, 213L, 
214L, 215L, 323L, 324L, 925L, 926L, 927L, 928L, 929L, 930L, 987L, 
988L, 989L, 990L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 51L, 
52L, 912L, 913L, 914L, 915L, 916L, 59L, 60L, 62L, 63L, 240L, 
901L, 902L, 903L, 904L, 905L, 907L, 908L, 909L, 22L, 23L, 937L, 
938L, 939L, 976L, 977L, 979L, 980L, 981L, 985L, 986L), site = c(12L, 
7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 23L, 23L, 23L, 23L, 23L, 
23L, 16L, 16L, 16L, 16L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 16L, 
16L, 16L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 23L, 23L, 23L, 
23L, 23L, 23L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 12L, 12L, 23L, 23L, 23L, 23L, 23L, 12L, 12L, 12L, 12L, 
7L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 12L, 12L, 23L, 23L, 
23L, 16L, 16L, 16L, 16L, 16L, 16L, 16L), stem = c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), heightPre = c(58, 50, 38, 33, 28, 
18, 20, 28, 47, 118, 109, 103, 99, 79, 69, 73, 54, 33, 32.5, 
74, 67, 57, 77, 49, 45, 58, 89, 49, 33, 37, 69, 53, 64, 49, 70, 
36, 59, 66.5, 21, 36.5, 59, 37, 59, 55, 33, 27, 35, 41, 65, 56, 
37, 53, 73, 59, 16, 51, 37, 77, 79, 45, 68, 75, 110, 56, 115, 
42, 90, 107, 86.5, 37, 113, 211, 130, 175, 135, 175, 122, 66, 
115, 167, 84, 63.5, 144, 16, 51, 45, 54, 32, 70, 53), height1mo = c(0, 
0, 0, 0, 0, 0, 0, 6, 10, 15, 25.5, 25, 26.5, 20, 19.5, 18, 19, 
8.5, 20, 12, 7.5, 4, 7, 0, 4, 11, 3, 9, 3.5, 12.5, 10, 12.5, 
19, 17.5, 11.5, 7, 12, 14, 18, 18, 3, 3.5, 6, 1, 9, 0.5, 7.5, 
9, 17, 15, 1.5, 7.5, 14, 18, 5, 4.5, 6, 15.5, 15, 2, 0.5, 0, 
12, 0, 5, 0, 0, 0, 0, 0, 37, 31, 14, 0, 20, 35, 0, 39, 0, 0, 
21, 7, 12, 11, 23.5, 15, 26, 7, 5, 17), height2mo = c(2.5, 7.5, 
9, 10, 12, 0, 8, 23, 34, 26.5, 57, 49, 57.5, 41, 43, 28, 29, 
11, 29.5, 20, 21, 20, 10, 7, 11, 22.5, 13, 21, 17.5, 29.5, 24.5, 
38, 53, 49, 44, 19, 38, 49, 37, 40, 10, 0, 18, 8.5, 19.5, 0.5, 
9, 23, 29, 22, 6.5, 26, 36.5, 39, 15, 12.5, 13.5, 30, 45, 16.5, 
2, 0, 14, 20, 43, 0.5, 1, 1, 0, 0, 86, 106, 59, 0, 67, 83, 32, 
83, 3, 4.5, 49, 9.5, 43, 20, 35, 16, 27, 7, 7, 26.5), height4mo = c(7, 
11.5, 10, 8.5, 17, 6.5, 8.5, 26, 34, 33, 62.5, 51.5, 61, 42.5, 
46.5, 29, 30, 11.5, 26.5, 20, 23, 29, 11.5, 21, 12.5, 25, 15.5, 
24, 28.5, 37, 51, 46, 60.5, 55, 53, 25, 49, 56, 40, 43, 23, 8, 
16, 8.5, 19.5, 2.5, 9.5, 22.5, 21, 20, 6.5, 31, 42, 45, 15, 17.5, 
13.5, 36.5, 47, 20, 13, 18, 20, 27.5, 70, 31, 21, 25, 42, 12, 
89, 128, 64, 45, 69, 84.5, 32, 86, 31, 31, 50, 10, 49.5, 20, 
42.5, 15, 38, 7.5, 13, 33), PreBiomass = c(3.895575649, 2.834165975, 
1.573928396, 1.163246736, 0.817978445, 0.317316605, 0.39770427, 
0.817978445, 2.48217785, 17.85049586, 12.66281683, 11.31037967, 
10.45107234, 6.662611474, 5.086139353, 5.691293433, 3.119036919, 
1.167754804, 1.13272457, 5.847881474, 5.365833116, 3.999508626, 
6.910020728, 3.038057965, 2.602293243, 4.127993434, 8.991590789, 
3.038057965, 1.480678454, 1.823048057, 2.062949335, 1.18423519, 
1.760986422, 1.004008739, 2.126354774, 0.524854338, 1.483984987, 
1.908835132, 0.168869468, 0.540308647, 5.375747945, 2.053683314, 
5.375747945, 4.65118718, 1.622061536, 1.072373896, 1.831323212, 
2.537878044, 6.564139518, 4.827265975, 2.156129781, 5.153936858, 
11.20247906, 6.684694751, 0.282366443, 4.694933633, 2.156129781, 
12.74952183, 13.56745754, 3.465912243, 7.799750512, 9.849322745, 
24.51741906, 4.912423703, 27.25487445, 2.476234093, 15.20382114, 
22.9550974, 13.83353724, 1.831101565, 33.25213131, 139.5296871, 
45.87772104, 90.79892694, 50.03156249, 90.79892694, 39.65094302, 
9.671283982, 34.61929294, 81.54741169, 26.00946401, 14.01849263, 
85.55945731, 0.667045516, 8.637292691, 6.550744926, 9.799815468, 
3.084543759, 17.38618089, 9.403377144), Biomass1mo = c(0, 0, 
0, 0, 0, 0, 0, 0.030124963, 0.090031144, 0.214679983, 0.698192549, 
0.67114866, 0.75387857, 0.430024245, 0.408844585, 0.348506855, 
0.388198419, 0.078012828, 0.430024245, 0.155212563, 0.296240906, 
0.112200441, 0.26629734, 0, 0.112200441, 0.535234264, 0.071949318, 
0.39259111, 0.091290587, 0.652064296, 0.094858153, 0.142288516, 
0.304507388, 0.262240101, 0.122283739, 0.04961378, 0.132115845, 
0.174825154, 0.276013506, 0.276013506, 0.022723782, 0.030242664, 
0.082163804, 0.002963157, 0.174263551, 0.000819511, 0.124274142, 
0.174263551, 0.566729877, 0.449345809, 0.01811283, 0.21782346, 
0.57145776, 0.842645845, 0.116410145, 0.09891947, 0.154294203, 
0.668793517, 0.635749905, 0.028252321, 0.005400266, 0, 0.308521938, 
0, 0.101231381, 0, 0, 0, 0, 0, 3.291544691, 2.308284799, 0.468693323, 
0, 0.958429423, 2.944402977, 0, 3.658082992, 0, 0, 1.524728852, 
0.19037959, 0.528356631, 0.448087868, 1.886696465, 0.806223299, 
2.284810808, 0.19037959, 0.10066607, 1.021875261), Biomass2mo = c(0.00461379, 
0.048598634, 0.071833216, 0.090031144, 0.133074246, 0, 0.055807842, 
0.536596536, 1.24010478, 0.726931224, 3.474265098, 2.569451142, 
3.535326978, 1.800572943, 1.980042107, 0.841402428, 0.902414303, 
0.130479556, 0.933718887, 0.430024245, 1.453050159, 1.347577447, 
0.461969077, 0.26629734, 0.535234264, 1.616437082, 0.6927849, 
1.453050159, 1.09644076, 2.456139386, 0.483312867, 1.0729993, 
1.964067221, 1.703060052, 1.400530346, 0.304507388, 1.0729993, 
1.703060052, 1.0222427, 1.177817154, 0.211862783, 0, 0.630095648, 
0.156738681, 0.730913281, 0.000819511, 0.174263551, 0.992673892, 
1.525735605, 0.914132292, 0.174609348, 1.487410339, 2.512370265, 
2.7832013, 0.635749905, 0.479653397, 0.540228204, 1.855529897, 
3.472016487, 0.736631727, 0.031533874, 0, 0.375407219, 0.591122274, 
1.566167617, 0.005400266, 0.013049571, 0.013049571, 0, 0, 17.86670522, 
27.17489168, 8.39141448, 0, 10.82904112, 16.63862372, 2.460045699, 
16.63862372, 0.021336774, 0.048116873, 7.586947075, 0.339458495, 
5.924289588, 1.390158514, 4.011712305, 0.911037264, 2.454089599, 
0.19037959, 0.19037959, 2.368736511), Biomass4mo = c(0.041918611, 
0.121473174, 0.090031144, 0.063551149, 0.280731338, 0.035762566, 
0.063551149, 0.697852512, 1.24010478, 1.163246736, 4.175122771, 
2.837608296, 3.977614516, 1.934377716, 2.314568827, 0.902414303, 
0.96555584, 0.142578593, 0.75387857, 0.430024245, 1.672251324, 
2.392140111, 0.573271986, 1.453050159, 0.652064296, 1.902090818, 
0.909034181, 1.785867231, 2.328738868, 3.484981432, 1.831472627, 
1.518350095, 2.498057072, 2.100814509, 1.964067221, 0.501385136, 
1.703060052, 2.170736601, 1.177817154, 1.343229421, 0.992673892, 
0.140073002, 0.506470737, 0.156738681, 0.730913281, 0.016205216, 
0.192640481, 0.953030318, 0.838582725, 0.766045551, 0.174609348, 
1.951972553, 3.12089825, 3.472016487, 0.635749905, 0.806750379, 
0.540228204, 2.512370265, 3.713345005, 0.991640221, 0.341613273, 
0.516931045, 0.591122274, 0.886590001, 2.912202284, 1.032643803, 
0.628997882, 0.785297256, 1.519953371, 0.308521938, 19.13863569, 
39.66748749, 9.878452915, 4.874133229, 11.48709241, 17.24718389, 
2.460045699, 17.86670522, 2.308284799, 2.308284799, 7.882847273, 
0.374087949, 7.734229305, 1.390158514, 5.794509429, 0.806223299, 
4.687787249, 0.21695254, 0.614836496, 3.588685645), PreCarbon = c(0.156967627, 
0.122843082, 0.075813652, 0.059169491, 0.044340523, 0.020426006, 
0.024570672, 0.043002708, 0.106999734, 0.545053086, 0.320308244, 
0.290501628, 0.271291986, 0.183819859, 0.145631674, 0.160452129, 
0.095815131, 0.041269875, 0.0402085, 0.164611233, 0.206240523, 
0.161958253, 0.253981948, 0.129206528, 0.113781088, 0.166223479, 
0.31553078, 0.129335339, 0.071711875, 0.085049069, 0.09317797, 
0.056638382, 0.080836829, 0.04885422, 0.09574618, 0.027353778, 
0.069332271, 0.086903123, 0.009475442, 0.026773874, 0.160707434, 
0.070160311, 0.160707434, 0.141844012, 0.057277905, 0.04013973, 
0.063665515, 0.084295725, 0.191213272, 0.146673529, 0.04757003, 
0.100344991, 0.195222186, 0.125396417, 0.008354372, 0.092637319, 
0.04757003, 0.218128582, 0.230401206, 0.07162901, 0.131269005, 
0.157389096, 0.320282156, 0.091653711, 0.347792395, 0.054313153, 
0.221509506, 0.305003004, 0.205854943, 0.043576888, 1.197871953, 
3.518128126, 1.526275089, 2.548979546, 1.629080226, 2.548979546, 
1.367623475, 0.472267765, 1.236694558, 2.352499024, 0.638415034, 
0.362069714, 1.904909524, 0.022514492, 0.232778297, 0.18076034, 
0.261297274, 0.090855905, 0.441867498, 0.25160457), X1moCarbon = c(0, 
0, 0, 0, 0, 0, 0, 0.002996291, 0.00733127, 0.014924131, 0.027262412, 
0.026357968, 0.02910929, 0.018027068, 0.017267076, 0.015069346, 
0.016555346, 0.004223662, 0.018064917, 0.007582482, 0.025240181, 
0.011434171, 0.023138557, 0, 0.011434171, 0.040903752, 0.007959618, 
0.031793903, 0.009674612, 0.048110681, 0.007167162, 0.009865614, 
0.017984257, 0.015981995, 0.00875496, 0.004302588, 0.009305238, 
0.011605185, 0.015676514, 0.015676514, 0.001435067, 0.001828411, 
0.004266066, 0.000255474, 0.008072101, 8.6e-05, 0.006067683, 
0.008083206, 0.022002661, 0.018064652, 0.000900408, 0.009931103, 
0.025212867, 0.036698014, 0.005423393, 0.004634604, 0.007118678, 
0.029351971, 0.028106107, 0.001391831, 0.000170474, 0, 0.00861976, 
0, 0.002921775, 0, 0, 0, 0, 0, 0.145554027, 0.112095861, 0.034715829, 
0, 0.058726823, 0.134088229, 0, 0.157321152, 0, 0, 0.046764496, 
0.007082034, 0.017870499, 0.015406694, 0.056813876, 0.026251236, 
0.067611463, 0.007089935, 0.003979541, 0.032552937), X2moCarbon = c(0.000649991, 
0.004515538, 0.006213783, 0.007472947, 0.010284713, 0, 0.005055737, 
0.031163252, 0.061950899, 0.03996902, 0.104905954, 0.080952912, 
0.106489463, 0.0596727, 0.064736059, 0.031121663, 0.033108443, 
0.006368256, 0.034087686, 0.017584511, 0.090428862, 0.085023956, 
0.035457668, 0.022619457, 0.039985244, 0.098665234, 0.04936287, 
0.090524095, 0.071905993, 0.139112044, 0.01893176, 0.035575351, 
0.057471358, 0.051317148, 0.043939693, 0.013147169, 0.035575351, 
0.051317148, 0.032779136, 0.036681952, 0.010956757, 0, 0.027658897, 
0.008484002, 0.031380578, 9.89e-05, 0.009296871, 0.040783331, 
0.058816936, 0.038019773, 0.008653254, 0.068600624, 0.113960148, 
0.125843837, 0.030152569, 0.022965412, 0.025762347, 0.084974223, 
0.156538314, 0.034969776, 0.000617961, 0, 0.006829998, 0.010617342, 
0.027416033, 0.000112755, 0.000265127, 0.000265127, 0, 0, 0.893643875, 
1.221422984, 0.50961417, 0, 0.615827082, 0.847505481, 0.205500657, 
0.847505481, 0.006343264, 0.011521572, 0.304122678, 0.017974685, 
0.242561906, 0.064815574, 0.170213577, 0.04413614, 0.108738758, 
0.010654473, 0.010654473, 0.105287901), X4moCarbon = c(0.003939148, 
0.009545784, 0.007472947, 0.005621946, 0.018936017, 0.003514856, 
0.005621946, 0.038653227, 0.061950899, 0.058780944, 0.122873324, 
0.088156055, 0.117853953, 0.063453978, 0.074010607, 0.03304018, 
0.035078824, 0.006867286, 0.028392571, 0.017584511, 0.101443992, 
0.135990762, 0.042290614, 0.090428862, 0.046980199, 0.112718863, 
0.061628519, 0.10716323, 0.133173424, 0.185313121, 0.054366886, 
0.046847602, 0.069583598, 0.060629528, 0.057471358, 0.019488753, 
0.051317148, 0.062228442, 0.036681952, 0.040720029, 0.040718675, 
0.007712115, 0.022971487, 0.008484002, 0.031380578, 0.001238836, 
0.010122608, 0.039392597, 0.035328505, 0.032710879, 0.008653254, 
0.089246941, 0.140615722, 0.155927128, 0.030152569, 0.037960536, 
0.025762347, 0.113960148, 0.167057162, 0.046603193, 0.006232079, 
0.009319662, 0.010617342, 0.01574909, 0.050249507, 0.018386847, 
0.011359619, 0.014091865, 0.026775581, 0.005739173, 0.940599218, 
1.618014419, 0.57521217, 0.340713733, 0.643414594, 0.870471728, 
0.205500657, 0.893643875, 0.198091533, 0.198091533, 0.314956518, 
0.01963135, 0.309519324, 0.064815574, 0.23812921, 0.039496022, 
0.196215504, 0.011995076, 0.030876347, 0.153759364), TotalCarbon = c(2.501938424, 
2.332218951, 1.641013423, 1.392483377, 1.696000406, 0.411835774, 
0.764726634, 3.251928154, 6.361282467, 11.96169249, 13.62052751, 
11.04045665, 12.83366357, 7.61659474, 7.576922118, 5.024502369, 
4.227801803, 1.174993138, 3.259824259, 3.901744082, 10.5848291, 
10.50668723, 7.021121066, 5.668839356, 5.08697083, 10.92840985, 
8.922540693, 9.705419805, 8.451769698, 13.81683185, 3.988112769, 
4.003878786, 6.156035357, 5.100700715, 5.268944019, 1.651130691, 
4.319967871, 5.653749527, 2.952799027, 3.509044554, 4.146751849, 
1.311194265, 4.40839747, 2.767792413, 3.333793425, 0.645000544, 
1.768035403, 4.402711785, 6.904856277, 5.163288885, 1.376050648, 
7.418577716, 12.65320411, 12.77220297, 2.468109142, 3.631338446, 
2.75250667, 10.95485279, 15.93354872, 4.067048349, 2.1863628, 
2.640426289, 5.559398908, 2.325058743, 8.001919262, 1.371376664, 
3.675361853, 5.009731732, 3.891091568, 0.825828495, 88.5833406, 
157.9578266, 63.60386651, 48.45610517, 72.33176226, 104.4979151, 
35.92690142, 74.39089664, 24.77861122, 41.74870207, 33.41190899, 
6.935077567, 49.04256584, 5.429985864, 19.14736986, 6.276180599, 
15.71334028, 2.308491154, 8.093447265, 13.61309907), OLDestAssim = c(0.16273292, 
0.531283865, 0.546784515, 0.548005831, 1.117252104, 0.114703735, 
0.430112005, 2.958994249, 5.413171027, 4.46316534, 10.53485645, 
8.109549494, 10.50791092, 5.898234837, 6.492409411, 3.283621134, 
3.499740655, 0.718250337, 3.370987696, 1.789036071, 8.664887392, 
9.086176264, 3.919440166, 4.123497491, 3.919792348, 9.950535196, 
4.756772076, 9.060767572, 8.278498547, 14.54720467, 4.724107286, 
5.766516948, 9.027313298, 7.989111013, 6.951312225, 2.28863022, 
5.981065361, 7.901084227, 5.4728181, 6.020818486, 1.853280059, 
0.311044291, 2.18794981, 0.68034361, 2.765418329, 0.047128668, 
0.980573348, 3.453418537, 4.673671847, 3.476060731, 0.646316335, 
5.778390351, 9.633196576, 10.92370219, 2.319186273, 2.209960947, 
2.058639203, 7.773645484, 12.22756086, 2.852689634, 0.386565881, 
0.496860166, 1.407968874, 1.680611096, 4.916640727, 0.977215919, 
0.620253347, 0.763829673, 1.409081851, 0.302135427, 44.7470637, 
63.92221417, 24.86052444, 6.076027823, 29.59811425, 41.96954834, 
9.196665562, 43.0963223, 3.680815508, 3.819136463, 19.30141334, 
1.332232454, 16.07431445, 4.286639367, 13.30975772, 3.365326795, 
10.62150582, 0.898527189, 1.227305975, 8.317751517), CARBONmulti = c(2.621415393, 
2.398836005, 1.641013423, 1.392483377, 1.696000406, 0.411835774, 
0.809806973, 3.251928154, 6.361282467, 11.96169249, 13.62052751, 
11.04045665, 12.83366357, 7.61659474, 7.576922118, 5.024502369, 
4.227801803, 1.174993138, 4.510076237, 3.901744082, 18.5717312, 
10.50668723, 7.021121066, 8.059558949, 5.08697083, 10.92840985, 
11.70126006, 16.07362835, 9.527447818, 21.36601039, 4.377265297, 
4.003878786, 6.156035357, 6.514095673, 5.268944019, 2.169858768, 
4.319967871, 5.653749527, 2.952799027, 4.588995837, 4.705122057, 
1.542557708, 6.195249968, 2.767792413, 3.480946773, 0.645000544, 
1.768035403, 4.961955587, 6.904856277, 5.163288885, 1.765904086, 
7.418577716, 12.65320411, 12.77220297, 2.468109142, 3.631338446, 
3.441469031, 15.95980398, 15.93354872, 4.067048349, 2.1863628, 
2.640426289, 6.723791976, 2.325058743, 8.001919262, 1.857730159, 
3.675361853, 5.330578088, 3.891091568, 0.825828495, 88.5833406, 
157.9578266, 63.60386651, 48.45610517, 82.73192555, 106.3419007, 
35.92690142, 74.66251592, 24.77861122, 41.74870207, 35.0178608, 
6.935077567, 49.04256584, 5.429985864, 19.14736986, 6.276180599, 
23.40428597, 2.308491154, 8.093447265, 13.61309907), RecBiomass = c(0.010760569, 
0.042860289, 0.05720155, 0.054632562, 0.343201388, 0.112703103, 
0.159794989, 0.853142911, 0.499603516, 0.065166074, 0.329715167, 
0.250885327, 0.380593913, 0.290333261, 0.455073813, 0.158560495, 
0.309568583, 0.122096345, 0.665544467, 0.073535048, 0.311648031, 
0.598108502, 0.082962412, 0.478282566, 0.25057295, 0.460778547, 
0.10109826, 0.587831849, 1.572751236, 1.911623458, 0.887793314, 
1.282135599, 1.418555556, 2.092426518, 0.923678046, 0.955284351, 
1.1476262, 1.137204866, 6.974719413, 2.48604095, 0.184657819, 
0.068205746, 0.094214004, 0.03369864, 0.450607616, 0.015111536, 
0.105191962, 0.375522504, 0.127752118, 0.158691391, 0.080982764, 
0.378734278, 0.278589965, 0.519397911, 2.25150658, 0.171834246, 
0.250554586, 0.197056039, 0.273694979, 0.286112328, 0.043797974, 
0.052483918, 0.024110298, 0.180479139, 0.106850695, 0.417021883, 
0.041371039, 0.034210147, 0.109874528, 0.168489801, 0.575561173, 
0.284294248, 0.215321352, 0.053680516, 0.229596915, 0.189949204, 
0.062042552, 1.847397435, 0.066676255, 0.028306046, 0.303076114, 
0.026685319, 0.09039596, 2.084053457, 0.670871028, 0.123073529, 
0.478354645, 0.070335374, 0.035363517, 0.381637957), RecovCarbonMULTI = c(0.672921188, 
0.846399267, 1.042622667, 1.197066224, 2.073404766, 1.297870225, 
2.03620387, 3.975567052, 2.562782706, 0.670104214, 1.075631725, 
0.976134929, 1.227975767, 1.143184586, 1.489719725, 0.882840154, 
1.355483091, 1.006198505, 3.981617736, 0.667206423, 3.461108611, 
2.626994517, 1.016078148, 2.65286543, 1.954803074, 2.647390319, 
1.301355937, 5.290757627, 6.434515065, 11.7199381, 2.121848182, 
3.380982781, 3.495788088, 6.488086629, 2.477923291, 4.134211359, 
2.911059012, 2.961884676, 17.4856892, 8.493285951, 0.875249752, 
0.751117613, 1.15244428, 0.595072248, 2.146001675, 0.601469829, 
0.965441486, 1.955159193, 1.051905777, 1.069609363, 0.819015674, 
1.439400194, 1.129500358, 1.910663604, 8.740801894, 0.773458952, 
1.596132599, 1.251796278, 1.174394589, 1.173442391, 0.280311889, 
0.268082015, 0.274245505, 0.473301752, 0.293595895, 0.750223965, 
0.241739351, 0.23221762, 0.281279582, 0.451000923, 2.663989859, 
1.132073252, 1.386378073, 0.533663853, 1.65359468, 1.171180148, 
0.906079369, 7.72002105, 0.715745734, 0.511956188, 1.346350728, 
0.494709221, 0.573198655, 8.14035284, 2.216825404, 0.958086549, 
2.388237416, 0.748406032, 0.465510357, 1.447681919), LogRespBiomass = c(-3.172025374, 
-2.108061831, -2.407599624, -2.755910201, -1.27035716, -3.330853575, 
-2.755910201, -0.359747499, 0.215195876, 0.151215006, 1.429143764, 
1.042961548, 1.380682272, 0.659785681, 0.839223418, -0.102681548, 
-0.035051343, -1.947861901, -0.282523972, -0.843913688, 0.514170817, 
0.872188409, -0.556395005, 0.373664905, -0.427612108, 0.642953712, 
-0.095372583, 0.579904141, 0.845326863, 1.248462716, 0.605120357, 
0.417624281, 0.915513259, 0.742325131, 0.675017436, -0.690380739, 
0.532426664, 0.775066557, 0.163662856, 0.29507673, -0.007353076, 
-1.965591549, -0.680288732, -1.853175313, -0.313460457, -4.122422113, 
-1.64692962, -0.048108563, -0.176042044, -0.266513645, -1.745204097, 
0.668840427, 1.138120861, 1.244735545, -0.452950024, -0.214740978, 
-0.615763629, 0.921226636, 1.311933089, -0.008394918, -1.074075962, 
-0.659845789, -0.52573239, -0.120372635, 1.068909594, 0.032122313, 
-0.46362739, -0.241692963, 0.418679657, -1.175962326, 2.951709103, 
3.680531897, 2.290355912, 1.583942289, 2.441224006, 2.847648877, 
0.900179927, 2.882938937, 0.836504737, 0.836504737, 2.064689168, 
-0.983264351, 2.045655842, 0.329417779, 1.756910819, -0.215394529, 
1.544960669, -1.528076659, -0.486398907, 1.27778602), LogPreBiomass = c(1.35984146, 
1.041747705, 0.453574657, 0.151215006, -0.200919294, -1.14785525, 
-0.92204659, -0.200919294, 0.90913634, 2.882031287, 2.53866989, 
2.425720859, 2.346704589, 1.896511521, 1.626519066, 1.738937539, 
1.137524274, 0.155082934, 0.124625855, 1.766079454, 1.680051651, 
1.38617151, 1.932972637, 1.111218484, 0.956393073, 1.417791438, 
2.196289784, 1.111218484, 0.392500398, 0.600509857, 0.724136675, 
0.169097157, 0.565874119, 0.004000725, 0.75440914, -0.644634506, 
0.394731028, 0.646493177, -1.778629241, -0.615614734, 1.681897717, 
0.719634919, 1.681897717, 1.537122495, 0.483697893, 0.069874785, 
0.605038772, 0.931328316, 1.881621428, 1.574280257, 0.768314847, 
1.639760861, 2.416135098, 1.899820548, -1.264549608, 1.546483977, 
0.768314847, 2.545493767, 2.607674097, 1.242975872, 2.054091748, 
2.287402696, 3.199383847, 1.591767446, 3.305232384, 0.906738895, 
2.721546787, 3.133540021, 2.627095879, 0.604917734, 3.504118865, 
4.938277389, 3.825979619, 4.508647468, 3.912654056, 4.508647468, 
3.680114731, 2.269161081, 3.544411126, 4.40118459, 3.258460472, 
2.64037736, 4.449211541, -0.404896996, 2.156089188, 1.879578772, 
2.282363556, 1.126403756, 2.855675689, 2.241068895), LogRecBio = c(-4.531866845, 
-3.149809546, -2.861174283, -2.9071252, -1.069437867, -2.182998325, 
-1.833863604, -0.158828206, -0.693940463, -2.730816283, -1.109526128, 
-1.382759309, -0.966022317, -1.23672584, -0.787295647, -1.841619087, 
-1.172575619, -2.102944833, -0.407149826, -2.609993143, -1.165880834, 
-0.5139831, -2.489367641, -0.737553579, -1.384005183, -0.774837727, 
-2.291662364, -0.531314343, 0.452826465, 0.647952859, -0.119016318, 
0.248527124, 0.34963914, 0.738324406, -0.079391703, -0.045746233, 
0.137695635, 0.12857338, 1.942292099, 0.910691465, -1.689250794, 
-2.685226465, -2.362186446, -3.390297799, -0.797158349, -4.192296853, 
-2.251968388, -0.979436879, -2.057663471, -1.8407939, -2.513518937, 
-0.970920433, -1.278014238, -0.655085002, 0.811599583, -1.761224953, 
-1.384078474, -1.624267129, -1.295741008, -1.25137079, -3.128167718, 
-2.94724848, -3.725116227, -1.712140081, -2.236322793, -0.874616581, 
-3.185174184, -3.375232983, -2.208416219, -1.780880059, -0.552409761, 
-1.257745493, -1.535623706, -2.924705174, -1.471430051, -1.66099859, 
-2.779934807, 0.613777857, -2.707906386, -3.564679858, -1.193771304, 
-3.623641715, -2.403555703, 0.734314775, -0.399178369, -2.094973305, 
-0.737402886, -2.65448042, -3.342074583, -0.963282876), LogCarbAss = c(0.963714398, 
0.874983622, 0.495313992, 0.331088755, 0.528272777, -0.887130616, 
-0.210959365, 1.179248099, 1.850230003, 2.481709251, 2.611578031, 
2.401566403, 2.552071685, 2.030329385, 2.025107064, 1.614326418, 
1.44168219, 0.161262308, 1.506314057, 1.361423654, 2.921640597, 
2.352011933, 1.948922901, 2.086858834, 1.626682532, 2.391365807, 
2.459696533, 2.777179938, 2.254176877, 3.06180136, 1.476424168, 
1.387263588, 1.817432959, 1.873968394, 1.661829967, 0.774662082, 
1.463247965, 1.732318958, 1.082753543, 1.523661228, 1.548651715, 
0.433441888, 1.823782864, 1.01805004, 1.247304318, -0.438504119, 
0.569868988, 1.601799935, 1.932224972, 1.641573757, 0.568662789, 
2.003987356, 2.537910472, 2.547271167, 0.903452328, 1.289601298, 
1.235898424, 2.77007331, 2.768426869, 1.402917515, 0.782239341, 
0.970940377, 1.905652278, 0.843745305, 2.079681421, 0.619355398, 
1.301651591, 1.673459692, 1.358689727, -0.19136816, 4.483943811, 
5.062328077, 4.152674263, 3.88065834, 4.415605568, 4.666659382, 
3.581486358, 4.312978171, 3.20998083, 3.731668363, 3.55585824, 
1.936592239, 3.892688612, 1.691936531, 2.952165362, 1.836761611, 
3.152919167, 0.836594131, 2.091054755, 2.611032496), LogRecCarb = c(-0.396127062, 
-0.166764084, 0.041739334, 0.17987375, 0.729192071, 0.260724633, 
0.711087226, 1.380167393, 0.941093663, -0.400322035, 0.07290814, 
-0.024154455, 0.205367096, 0.133817864, 0.398587998, -0.124611121, 
0.304157916, 0.006179373, 1.381688203, -0.404655801, 1.241588946, 
0.965840424, 0.015950264, 0.97564035, 0.670289459, 0.973574369, 
0.263406749, 1.665961454, 1.861676479, 2.461291503, 0.752287493, 
1.218166431, 1.25155884, 1.869967669, 0.907420827, 1.419296587, 
1.068516937, 1.085825781, 2.861382786, 2.139275963, -0.133246002, 
-0.286193031, 0.141885148, -0.519072456, 0.763606425, -0.508378904, 
-0.035169784, 0.670471619, 0.050603545, 0.067293501, -0.199652057, 
0.364226495, 0.121775374, 0.647450618, 2.168001935, -0.256882678, 
0.467583578, 0.224579542, 0.160752771, 0.159941643, -1.271852406, 
-1.316462319, -1.29373157, -0.74802214, -1.225550964, -0.287383497, 
-1.419895195, -1.46008033, -1.268406151, -0.796285893, 0.979824946, 
0.124050688, 0.326694644, -0.627989127, 0.502951512, 0.158011914, 
-0.098628373, 2.043817091, -0.334430295, -0.669516228, 0.297397768, 
-0.703785121, -0.55652293, 2.096833526, 0.796076174, -0.042817162, 
0.870555611, -0.289809625, -0.764620933, 0.369963601)), .Names = c("Treatment", 
"Species", "Tag", "site", "stem", "heightPre", "height1mo", "height2mo", 
"height4mo", "PreBiomass", "Biomass1mo", "Biomass2mo", "Biomass4mo", 
"PreCarbon", "X1moCarbon", "X2moCarbon", "X4moCarbon", "TotalCarbon", 
"OLDestAssim", "CARBONmulti", "RecBiomass", "RecovCarbonMULTI", 
"LogRespBiomass", "LogPreBiomass", "LogRecBio", "LogCarbAss", 
"LogRecCarb"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 46L, 
47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 105L, 106L, 107L, 
108L, 109L, 110L, 111L, 112L, 113L, 114L, 123L, 124L, 125L, 126L, 
127L, 128L, 129L, 130L, 131L, 132L, 172L, 173L, 174L, 175L, 176L, 
177L, 178L, 179L, 180L, 181L, 227L, 228L, 229L, 230L, 231L, 232L, 
233L, 234L, 235L, 236L, 255L, 256L, 257L, 258L, 259L, 260L, 261L, 
262L, 263L, 264L, 290L, 291L, 292L, 293L, 294L, 295L, 296L, 297L, 
298L, 299L), class = "data.frame")

2 个答案:

答案 0 :(得分:2)

在回复评论时,如果您使用ggplot2,这就是您的代码的样子。

DF<-read.csv("test.csv")
require(ggplot2)
qplot(data=DF,x=LogPreBiomass,y=LogRecBio,facets=~Species)

我将您的样本保存为名为test.csv的.csv文件。这对您有用吗?

enter image description here

答案 1 :(得分:2)

这应该适用于简单的graphics包。您需要添加真实的科学名称,其顺序与它们在物种中列出的顺序相同。如果您想要不同的订单,也可以手动设置species

species = unique(carbon2$Species) # c("Acru", "Arte", ...)
bin.name = c("Acer rubrum", "Arundinaria tecta", "Clethra alnifolia",
             "Eupatorium rotundifolium", "Gaylussacia frondosa", 
             "Ilex glabra", "Lyonia lucida", "Oxydendrum arboreum",
             "Persea palustris")

sites = c(7,8) # sites to use
color = c("blue", "green") # colors for each site

fit.bio = list() # list to save all models

par(mfrow=c(3,3), cex=.3) 

for(isp in seq_along(species)) {

  sp.data = carbon2[carbon2$Species==species[isp], ] 

  fit.bio[[isp]] <- lm(LogRecBio ~ LogPreBiomass, data=sp.data)

  sp.label     = paste(letters[isp], ") ", bin.name[isp], sep="")
  sp.r.squared = paste("R²", "=", round(summary(fit.bio[[isp]])$adj.r.squared, 3))
  plot(LogRecBio ~ LogPreBiomass, data=sp.data, 
       font.lab=2,font.main=2, font.sub=3, ylim=c(-5,4),
       mgp=c(2.5,1,0), cex.lab=2, cex.main=1.5, 
       axes=FALSE, lwd=1.5, cex=2.5, ann=FALSE)

  for(isite in seq_along(sites)) {
    # loop for each selected site
    site.data  = sp.data[sp.data$site==sites[isite], ]
    site.model = lm(LogRecBio ~ LogPreBiomass, data=site.data)
    abline(site.model, lwd=2, col=color[isite])

  }

  abline(fit.bio[[isp]], lwd=2, col='red') # all data

  axis(1,at=c(-2,-1,0,1,2,3,4),font=2,cex.axis=3)
  axis(2,at=c(-5,-4,-3,-2,-1,0,1,2),font=2,cex.axis=3)
  box()

  mtext(sp.label, 3, line=-2.5, adj=0.05, font=3, cex=0.75)
  mtext(sp.r.squared, 3, line=-2.5, adj=0.95, cex=0.75)

}

theplot