time ## y-axis is …
something that changes over time
Time series plot - Wolves of Yellowstone NP
Classic time series
Can be plotted in 2 easy steps
## year.1.15.
## 1 1995
## 2 1996
## 3 1997
## 4 1998
## 5 1999
## 6 2000
## 7 2001
## 8 2002
## 9 2003
## 10 2004
## 11 2005
## 12 2006
## 13 2007
## 14 2008
## 15 2009
## [1] 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
## [16] 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
## year packs wolves
## 1 1995 3.0 21
## 2 1996 9.0 51
## 3 1997 9.0 86
## 4 1998 11.0 112
## 5 1999 11.0 118
## 6 2000 8.0 119
## 7 2001 10.0 132
## 8 2002 14.0 148
## 9 2003 13.5 174
## 10 2004 16.0 171
## 11 2005 13.0 118
## 12 2006 13.0 136
## 13 2007 11.0 171
## 14 2008 12.0 124
## 15 2009 14.0 96
## [1] 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
## [16] 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
## [1] 21 51 86 112 118 119 132 148 174 171 118 136 171 124 96 97 98 83 95
## [20] 104 98 108 97 80 94 123
length() command determines the number of elements
in a vector## [1] 26
## [1] 26
==== is an R function= is a different R function (That I don’t use)= is also used within arguments## [1] TRUE
## [1] 21 51 86 112 118 119
## [1] 6
## [1] FALSE
plot() he defaults are blahplot()
commandhist
for histogramsggplot and ggpubr use completely different
functionsmain = ...main = ... allows you to set the titleplot() command can plot points, lines or bothplot() command can plot points, lines or bothpar(mfrow = c(2,2), mar = c(2,2,4,1)) #ignore this line
plot(wolves ~ year, main = "(default)") # default
plot(wolves ~ year, type = "p", main = "type = 'p'") # type = "p"
plot(wolves ~ year, type = "l", main = "type = 'p'") # type = 'l'
plot(wolves ~ year, type = "b", main = "type = 'b'") # type = "l"col = ... set the COLORpar(mfrow = c(2,2), mar = c(2,2,4,1)) #ignore this line
plot(wolves ~ year, main = "(default)") # default
plot(wolves ~ year, col = 1, main = "col = 1") # black
plot(wolves ~ year, col = 2, main = "col = 2") # red
plot(wolves ~ year, col = 3, main = "col = 3") # greenpch = ... sets the type of pointpar(mfrow = c(2,2), mar = c(2,2,4,1)) #ignore this line
plot(wolves ~ year, main = "(default)")
plot(wolves ~ year, pch = 2, main = "pch = 2")
plot(wolves ~ year, pch = 10, main = "pch = 3")
plot(wolves ~ year, pch = 16, main = "pch = 16") pch values are in the teenspar(mfrow = c(2,2), mar = c(2,2,4,1)) #ignore this line
plot(wolves ~ year, pch = 15, main = "pch = 15")
plot(wolves ~ year, pch = 16, main = "pch = 16")
plot(wolves ~ year, pch = 17, main = "pch = 17")
plot(wolves ~ year, pch = 18, main = "pch = 18") xlab = ... sets x-axis labelylab = ... sets y- axis labelpar(mfrow = c(1,1), mar = c(4,4,4,4)) # ignore this
plot(wolves ~ year, pch = 16, col = 2, type = "b",
xlab = "Year",
ylab = "Wolves (N)") ggplot()c() function,# names
wolf_names <- c("white fang", "fluffy", "bingo","minnie", "percy")
# first name - uses 1 (not 0!)
wolf_names[1]## [1] "white fang"
## [1] "fluffy"
## [1] "white fang" "fluffy"
## [1] "fluffy" "bingo"
## [1] "white fang" "fluffy" "bingo" "minnie" "percy"
## [1] "fluffy" "bingo" "minnie" "percy"
## [1] "white fang" "bingo" "minnie" "percy"
## [1] "white fang"
## [1] "white fang" "fluffy"
## [1] 4
## [1] 4
## [1] TRUE
## [1] "A"
## [1] "A"
## [1] TRUE
## [1] "T"
## [1] "U"
## [1] FALSE
== has been applied to each pair of
elements## [1] TRUE FALSE TRUE TRUE
log() in Rlog10()lo2g()## [1] 2.302585
## [1] 1
## [1] 3.321928
## year packs wolves
## 1 7.598399 1.098612 3.044522
## 2 7.598900 2.197225 3.931826
## 3 7.599401 2.197225 4.454347
## 4 7.599902 2.397895 4.718499
## 5 7.600402 2.397895 4.770685
## 6 7.600902 2.079442 4.779123
## 7 7.601402 2.302585 4.882802
## 8 7.601902 2.639057 4.997212
## 9 7.602401 2.602690 5.159055
## 10 7.602900 2.772589 5.141664
## 11 7.603399 2.564949 4.770685
## 12 7.603898 2.564949 4.912655
## 13 7.604396 2.397895 5.141664
## 14 7.604894 2.484907 4.820282
## 15 7.605392 2.639057 4.564348
## 16 7.605890 2.397895 4.574711
## 17 7.606387 2.302585 4.584967
## 18 7.606885 2.302585 4.418841
## 19 7.607381 2.302585 4.553877
## 20 7.607878 2.397895 4.644391
## 21 7.608374 2.302585 4.584967
## 22 7.608871 2.397895 4.682131
## 23 7.609367 2.397895 4.574711
## 24 7.609862 2.197225 4.382027
## 25 7.610358 2.079442 4.543295
## 26 7.610853 2.197225 4.812184
## year packs wolves
## 1 189525 285.0 1995
## 2 189620 855.0 4845
## 3 189715 855.0 8170
## 4 189810 1045.0 10640
## 5 189905 1045.0 11210
## 6 190000 760.0 11305
## 7 190095 950.0 12540
## 8 190190 1330.0 14060
## 9 190285 1282.5 16530
## 10 190380 1520.0 16245
## 11 190475 1235.0 11210
## 12 190570 1235.0 12920
## 13 190665 1045.0 16245
## 14 190760 1140.0 11780
## 15 190855 1330.0 9120
## 16 190950 1045.0 9215
## 17 191045 950.0 9310
## 18 191140 950.0 7885
## 19 191235 950.0 9025
## 20 191330 1045.0 9880
## 21 191425 950.0 9310
## 22 191520 1045.0 10260
## 23 191615 1045.0 9215
## 24 191710 855.0 7600
## 25 191805 760.0 8930
## 26 191900 855.0 11685
Wolves per square mile
## year packs wolves
## 1 0.5700000 0.0008571429 0.00600000
## 2 0.5702857 0.0025714286 0.01457143
## 3 0.5705714 0.0025714286 0.02457143
## 4 0.5708571 0.0031428571 0.03200000
## 5 0.5711429 0.0031428571 0.03371429
## 6 0.5714286 0.0022857143 0.03400000
## 7 0.5717143 0.0028571429 0.03771429
## 8 0.5720000 0.0040000000 0.04228571
## 9 0.5722857 0.0038571429 0.04971429
## 10 0.5725714 0.0045714286 0.04885714
## 11 0.5728571 0.0037142857 0.03371429
## 12 0.5731429 0.0037142857 0.03885714
## 13 0.5734286 0.0031428571 0.04885714
## 14 0.5737143 0.0034285714 0.03542857
## 15 0.5740000 0.0040000000 0.02742857
## 16 0.5742857 0.0031428571 0.02771429
## 17 0.5745714 0.0028571429 0.02800000
## 18 0.5748571 0.0028571429 0.02371429
## 19 0.5751429 0.0028571429 0.02714286
## 20 0.5754286 0.0031428571 0.02971429
## 21 0.5757143 0.0028571429 0.02800000
## 22 0.5760000 0.0031428571 0.03085714
## 23 0.5762857 0.0031428571 0.02771429
## 24 0.5765714 0.0025714286 0.02285714
## 25 0.5768571 0.0022857143 0.02685714
## 26 0.5771429 0.0025714286 0.03514286
## year packs wolves
## 1 21.00000 0.03157895 0.2210526
## 2 21.01053 0.09473684 0.5368421
## 3 21.02105 0.09473684 0.9052632
## 4 21.03158 0.11578947 1.1789474
## 5 21.04211 0.11578947 1.2421053
## 6 21.05263 0.08421053 1.2526316
## 7 21.06316 0.10526316 1.3894737
## 8 21.07368 0.14736842 1.5578947
## 9 21.08421 0.14210526 1.8315789
## 10 21.09474 0.16842105 1.8000000
## 11 21.10526 0.13684211 1.2421053
## 12 21.11579 0.13684211 1.4315789
## 13 21.12632 0.11578947 1.8000000
## 14 21.13684 0.12631579 1.3052632
## 15 21.14737 0.14736842 1.0105263
## 16 21.15789 0.11578947 1.0210526
## 17 21.16842 0.10526316 1.0315789
## 18 21.17895 0.10526316 0.8736842
## 19 21.18947 0.10526316 1.0000000
## 20 21.20000 0.11578947 1.0947368
## 21 21.21053 0.10526316 1.0315789
## 22 21.22105 0.11578947 1.1368421
## 23 21.23158 0.11578947 1.0210526
## 24 21.24211 0.09473684 0.8421053
## 25 21.25263 0.08421053 0.9894737
## 26 21.26316 0.09473684 1.2947368
## year packs wolves
## 1 0.5700000 0.0008571429 0.00600000
## 2 0.5702857 0.0025714286 0.01457143
## 3 0.5705714 0.0025714286 0.02457143
## 4 0.5708571 0.0031428571 0.03200000
## 5 0.5711429 0.0031428571 0.03371429
## 6 0.5714286 0.0022857143 0.03400000
## 7 0.5717143 0.0028571429 0.03771429
## 8 0.5720000 0.0040000000 0.04228571
## 9 0.5722857 0.0038571429 0.04971429
## 10 0.5725714 0.0045714286 0.04885714
## 11 0.5728571 0.0037142857 0.03371429
## 12 0.5731429 0.0037142857 0.03885714
## 13 0.5734286 0.0031428571 0.04885714
## 14 0.5737143 0.0034285714 0.03542857
## 15 0.5740000 0.0040000000 0.02742857
## 16 0.5742857 0.0031428571 0.02771429
## 17 0.5745714 0.0028571429 0.02800000
## 18 0.5748571 0.0028571429 0.02371429
## 19 0.5751429 0.0028571429 0.02714286
## 20 0.5754286 0.0031428571 0.02971429
## 21 0.5757143 0.0028571429 0.02800000
## 22 0.5760000 0.0031428571 0.03085714
## 23 0.5762857 0.0031428571 0.02771429
## 24 0.5765714 0.0025714286 0.02285714
## 25 0.5768571 0.0022857143 0.02685714
## 26 0.5771429 0.0025714286 0.03514286
## [1] 21 51 86 112 118
## [1] 3 9 9 11 11
## [1] 1995 1996 1997 1998 1999
## [1] 21
## [1] 3
## [1] 7
## [1] 7
## [1] 7.000000 5.666667 9.555556 10.181818 10.727273 14.875000 13.200000
## [8] 10.571429 12.888889 10.687500 9.076923 10.461538 15.545455 10.333333
## [15] 6.857143 8.818182 9.800000 8.300000 9.500000 9.454545 9.800000
## [22] 9.818182 8.818182 8.888889 11.750000 13.666667
:## [1] 7.000000 5.666667
c()## [1] 21 51
## [1] 7.000000 5.666667
## [1] 5.666667 9.555556 10.181818 10.727273 14.875000 13.200000 10.571429
## [8] 12.888889 10.687500 9.076923 10.461538 15.545455 10.333333 6.857143
## [15] 8.818182 9.800000 8.300000 9.500000 9.454545 9.800000 9.818182
## [22] 8.818182 8.888889 11.750000 13.666667