时间序列测量的图形表示

时间:2015-06-16 05:12:45

标签: r

我是这种语言的新手,我有一个名为`Dummy'的数据框。我试图按"年","家庭"和" HZ.CV"排序。

数据名为Dummy,包括:

(1) Family is the alpha-numeric code for a particular family of birds; 
(2) HZ.mean  is a mean pulse repetition rate (Hz); 
(3) HZ.sd is the standard deviation of the pulse repetition rate (Hz);  
(4) HZ.CV is the coefficient of variation (C.V. = (CV.sd/CV.mean)*100)

HZ.CV.是频率分布的分散度量。频率分布与频率(Hz)测量和不同鸟类家族的频谱图的可变性相关联。

* HZ代表脉冲重复率。

#Code to produce the dataframe called `Dummy`

Dummy$Year<-as.numeric(as.character(Dummy$Year))
Dummy$Family<-as.factor(Dummy$Family)
Dummy$HZ<-as.numeric(Dummy$HZ)

library(plyr)

summary.stats<-ddply(Dummy,.(Year,Family),summarise, 
HZ.mean=mean(HZ), HZ.sd = sd(HZ), HZ.CV = sd(HZ)/(mean(HZ))*(100))
summary.stats

  #I have two separate dataframes:
  (1) Showing families X75 and X87
  (2) Showing families X2 and X22, which diverged from the family X75 in 2006

 #Example of the dataframe format

 Year     Family      HZ.mean    HZ.sd        HZ.CV
1  2001    X75        15.00000   14.525839    96.83893
2  2001    X87        60.00000   31.320920    52.20153
3  2002    X75        68.00000   17.349352    25.51375
4  2002    X87        67.33333   14.843629    22.04499
5  2003    X75        50.00000   37.802116    75.60423
6  2003    X87        28.00000   35.791060    127.82522
7  2004    X75        40.66667   26.350206    64.79559
8  2004    X87        31.33333   24.172988    77.14783
9  2005    X75        31.33333   17.785762    56.76307
10 2005    X87        38.66667   28.884829    74.70214

问题

我想合并这两个数据帧,按照&#34;年&#34;对这些行进行排序。和&#34;家庭&#34;所以家庭&#34; X75&#34;,&#34; X87&#34;,&#34; X22&#34;,&#34; X4&#34;按年份的降序汇总在一起,以及显示HZ.CV变异性。目标是在时间序列中比较2006年之前和之后的模式。如果有人对如何最好地可视化这些模式有任何想法,那么谢谢你。

   After merging the dataframes: 

   merged.Dummy[order("Year","Family")]
   new.Dummy <- data.frame(merged.Dummy$Family[1:99])
   x=sample(LETTERS[1:4],4)

   combined.Dummy <- merge(Dummy, Dummy1, by=c("Year", "Family", "HZ.mean", "HZ.sd", "HZ.CV")) 
   merged.Dummy <- rbind(Dummy, Dummy1)
   merged.Dummy

#Arrange the data by just "Year", "Family", "HZ.CV":

merged.Dummy[,c("Year", "Family", "HZ.CV")]

*The new dataframe called `merged.Dummy` (below):

    Year Family      HZ.CV
1   2006    X22  66.666670
2   2006     X4  50.000000
3   2007    X22  50.000000
4   2007     X4  66.666670
5   2008    X22  66.666670
6   2008     X4  50.000000
7   2009    X22  50.000000
8   2009     X4  66.666670
9   2010    X22  66.666670
10  2010     X4  50.000000
11  2011    X22  50.000000
12  2011     X4  66.666670
13  2012    X22  66.666670
14  2012     X4  50.000000
15  2013    X22  50.000000
16  2013     X4  66.666670
17  2014    X22  66.666670
18  2014     X4  50.000000
19  1964    X75 105.249338
20  1964    X87   7.014259
21  1965    X75  78.507843
22  1965    X87  70.808548
23  1966    X75  25.101428
24  1966    X87  29.447163
25  1967    X75  67.395050
26  1967    X87  63.880988
27  1968    X75  67.857549
28  1968    X87  20.743852
29  1969    X75 145.284695
30  1969    X87  85.819272
31  1970    X75  60.806449
32  1970    X87  85.635091
33  1971    X75  71.595201
34  1971    X87  45.392863
35  1972    X75   8.845135
36  1972    X87  64.801549
37  1973    X75 119.192646
38  1973    X87  72.351927
39  1974    X75  50.024029
40  1974    X87 125.895232
41  1975    X75   7.733006
42  1975    X87  72.035520
43  1976    X75  23.977506
44  1976    X87  56.762990
45  1977    X75  37.055887
46  1977    X87  54.722673
47  1978    X75  76.765617
48  1978    X87 124.943928
49  1979    X75  86.444781
50  1979    X87  35.527844
51  1980    X75  12.882740
52  1980    X87  47.422399
53  1981    X75  74.266621
54  1981    X87  37.716625
55  1982    X75  45.465494
56  1982    X87  68.930631
57  1983    X75  16.600339
58  1983    X87  74.545714
59  1984    X75  42.897631
60  1984    X87  50.891461
61  1985    X75  41.374846
62  1985    X87   6.548454
63  1986    X75  73.292581
64  1986    X87  94.367915
65  1987    X75 134.677664
66  1987    X87  42.406152
67  1988    X75  13.588425
68  1988    X87  59.187538
69  1989    X75  87.600497
70  1989    X87 102.434045
71  1989    X75  58.104290
72  1990    X87  85.227130
73  1991    X75  43.961024
74  1991    X87 109.304906
75  1992    X75  29.329649
76  1992    X87  36.815668
77  1993    X75  25.727674
78  1993    X87  18.201273
79  1994    X75  86.583227
80  1994    X87  45.524410
81  1995    X75  45.530280
82  1995    X87  99.347994
83  1996    X75  37.480592
84  1996    X87  66.913808
85  1997    X75  53.528554
86  1997    X87  79.170739
87  1998    X75  52.208901
88  1998    X87  75.674816
89  1999    X75  13.855732
90  1999    X87  65.629371
91  2000    X75  73.891903
92  2000    X87  16.569935
93  2001    X75  50.819011
94  2001    X87  31.772731
95  2002    X75  57.510157
96  2002    X87  38.017454
97  2003    X75  39.984956
98  2003    X87  24.862990
99  2004    X75  25.825865

1 个答案:

答案 0 :(得分:1)

您可以通过多种方式对数据进行排序。这是使用包dplyr

的一个
library(dplyr)
merged.Dummy %>% arrange(Year, Family)
   Year Family     SBI.CV
# 1  1964    X75 105.249338
# 2  1964    X87   7.014259
# 3  1965    X75  78.507843
# 4  1965    X87  70.808548
# 5  1966    X75  25.101428
# 6  1966    X87  29.447163
# 7  1967    X75  67.395050
# ...

但是,在进行分析之前,您不需要对数据进行排序。

例如,如果您想查看多年来按组划分的变异系数

library(ggplot2)
ggplot(merged.Dummy, aes(Year, SBI.CV, color=Family)) + geom_path() +
  ggtitle("Coef. of Variation")

enter image description here