diff --git a/._timeseries.Rproj b/._timeseries.Rproj index 364cb68..b57fc73 100644 Binary files a/._timeseries.Rproj and b/._timeseries.Rproj differ diff --git a/.gitignore b/.gitignore index 807ea25..d893563 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .Rproj.user .Rhistory .RData +Meta diff --git a/Meta/vignette.rds b/Meta/vignette.rds index ff0a06f..0cbe8d7 100644 Binary files a/Meta/vignette.rds and b/Meta/vignette.rds differ diff --git a/doc/qstacktseries.R b/doc/qstacktseries.R new file mode 100644 index 0000000..a7ff05b --- /dev/null +++ b/doc/qstacktseries.R @@ -0,0 +1,36 @@ +## ---- include = FALSE--------------------------------------------------------- +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) + +## ----setup-------------------------------------------------------------------- +library(timeseries) +library(gapminder) +library(dplyr) + +## ----dataset------------------------------------------------------------------ + testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), + rainfall = c(runif(11, 0, 100), rnorm(11, 70, 10), + rnorm(11, 20, 20)), + temp = c(rnorm(11, 70, 30), rnorm(11, 45, 20), + rnorm(11, 100, 10)), + daysofsun = c(NA, NA, rnorm(9, 280, 50), rnorm(11, 300, 30), NA, + rnorm(10, 340, 15)), + region = c(rep("A",11), rep("B", 11), rep("C", 11))) + +## ----example 1---------------------------------------------------------------- +qstacktseries(testdf, year, rainfall, region, verbose = TRUE) + +## ----example 2---------------------------------------------------------------- +qstacktseries(gapminder %>% + filter(continent == "Asia"), year, gdpPercap, country, verbose = TRUE) + +## ----example 3: Errors, error=TRUE-------------------------------------------- + +qstacktseries(gapminder %>% + filter(continent == "Asia"),continent, pop, country, verbose = TRUE) + +qstacktseries(gapminder %>% + filter(continent == "Africa"), year, country, continent, verbose = TRUE) + diff --git a/doc/qstacktseries.Rmd b/doc/qstacktseries.Rmd new file mode 100644 index 0000000..c23bc21 --- /dev/null +++ b/doc/qstacktseries.Rmd @@ -0,0 +1,57 @@ +--- +title: "qstacktseries" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{qstacktseries} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(timeseries) +library(gapminder) +library(dplyr) +``` + +This is how the function `qstacktseries` works: + +Building a stacked area time series plot with a dummy data set: + +```{r dataset} + testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), + rainfall = c(runif(11, 0, 100), rnorm(11, 70, 10), + rnorm(11, 20, 20)), + temp = c(rnorm(11, 70, 30), rnorm(11, 45, 20), + rnorm(11, 100, 10)), + daysofsun = c(NA, NA, rnorm(9, 280, 50), rnorm(11, 300, 30), NA, + rnorm(10, 340, 15)), + region = c(rep("A",11), rep("B", 11), rep("C", 11))) +``` + +```{r example 1} +qstacktseries(testdf, year, rainfall, region, verbose = TRUE) +``` +Building a stacked area time series plot with a pre-existing data set: *gapminder* + +```{r example 2} +qstacktseries(gapminder %>% + filter(continent == "Asia"), year, gdpPercap, country, verbose = TRUE) +``` +These are some errors you might see if `qstacktseries` is given non-numeric input for the *time* or *voi* inputs: + +```{r example 3: Errors, error=TRUE} + +qstacktseries(gapminder %>% + filter(continent == "Asia"),continent, pop, country, verbose = TRUE) + +qstacktseries(gapminder %>% + filter(continent == "Africa"), year, country, continent, verbose = TRUE) +``` + diff --git a/doc/qstacktseries.html b/doc/qstacktseries.html new file mode 100644 index 0000000..e23927c --- /dev/null +++ b/doc/qstacktseries.html @@ -0,0 +1,375 @@ + + + + + + + + + + + + + + +qstacktseries + + + + + + + + + + + + + + + + + + + + + + +

qstacktseries

+ + + +
library(timeseries)
+library(gapminder)
+library(dplyr)
+#> 
+#> Attaching package: 'dplyr'
+#> The following objects are masked from 'package:stats':
+#> 
+#>     filter, lag
+#> The following objects are masked from 'package:base':
+#> 
+#>     intersect, setdiff, setequal, union
+

This is how the function qstacktseries works:

+

Building a stacked area time series plot with a dummy data set:

+
  testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3),
+                       rainfall = c(runif(11, 0, 100), rnorm(11, 70, 10),
+                                    rnorm(11, 20, 20)),
+                       temp = c(rnorm(11, 70, 30), rnorm(11, 45, 20), 
+                                rnorm(11, 100, 10)),
+                       daysofsun = c(NA, NA, rnorm(9, 280, 50), rnorm(11, 300, 30), NA, 
+                                     rnorm(10, 340, 15)),
+                       region = c(rep("A",11), rep("B", 11), rep("C", 11)))
+
qstacktseries(testdf, year, rainfall, region, verbose = TRUE)
+#> Plotting time series...Done labelling plot!...Done applying default theme aesthetics!
+

Building a stacked area time series plot with a pre-existing data set: gapminder

+
qstacktseries(gapminder %>%
+                filter(continent == "Asia"), year, gdpPercap, country, verbose = TRUE)
+#> Plotting time series...Done labelling plot!...Done applying default theme aesthetics!
+

These are some errors you might see if qstacktseries is given non-numeric input for the time or voi inputs:

+

+qstacktseries(gapminder %>%
+                filter(continent == "Asia"),continent, pop, country, verbose = TRUE)
+#> Error in qstacktseries(gapminder %>% filter(continent == "Asia"), continent, : Sorry, the time variable needs to be a numeric variable!
+
+qstacktseries(gapminder %>%
+                filter(continent == "Africa"), year, country, continent, verbose = TRUE)
+#> Error in qstacktseries(gapminder %>% filter(continent == "Africa"), year, : Sorry, the variable of interest (dependent) needs to be a numeric variable!
+ + + + + + + + + + + diff --git a/doc/qtseries.R b/doc/qtseries.R index 70faa7d..d046fcd 100644 --- a/doc/qtseries.R +++ b/doc/qtseries.R @@ -6,6 +6,8 @@ knitr::opts_chunk$set( ## ----setup-------------------------------------------------------------------- library(timeseries) +library(gapminder) +library(dplyr) ## ----dummy dataset setup------------------------------------------------------ testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), @@ -18,19 +20,13 @@ testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), qtseries(testdf, year, daysofsun, region, verbose = TRUE) ## ----example 2---------------------------------------------------------------- -library(gapminder) -library(magrittr) -library(dplyr) -gapminder %>% - filter(continent == "Europe")%>% - qtseries(year, pop, country, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Europe"), year, pop, country, verbose = TRUE) ## ----example 3: Errors, error=TRUE-------------------------------------------- -gapminder %>% - filter(continent == "Europe")%>% - qtseries(continent, pop, country, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Americas"),continent, pop, country, verbose = TRUE) -gapminder %>% - filter(continent == "Europe")%>% - qtseries(year, country, continent, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Europe"),year, country, continent, verbose = TRUE) diff --git a/doc/qtseries.Rmd b/doc/qtseries.Rmd index 40d8226..ca62a3e 100644 --- a/doc/qtseries.Rmd +++ b/doc/qtseries.Rmd @@ -16,11 +16,13 @@ knitr::opts_chunk$set( ```{r setup} library(timeseries) +library(gapminder) +library(dplyr) ``` This is how the function `qtseries` works: -Building a time series plot with a dummy data set +Building a time series plot with a dummy data set: ```{r dummy dataset setup} testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), @@ -34,24 +36,19 @@ testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), qtseries(testdf, year, daysofsun, region, verbose = TRUE) ``` -Building a time series plot with the gapminder data set: +Building a time series plot with the *gapminder* data set: ```{r example 2} -library(gapminder) -library(magrittr) -library(dplyr) -gapminder %>% - filter(continent == "Europe")%>% - qtseries(year, pop, country, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Europe"), year, pop, country, verbose = TRUE) ``` + Some errors you might see if `qtseries` is given non-numeric variables for the *time* or *voi* inputs: ```{r example 3: Errors, error=TRUE} -gapminder %>% - filter(continent == "Europe")%>% - qtseries(continent, pop, country, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Americas"),continent, pop, country, verbose = TRUE) -gapminder %>% - filter(continent == "Europe")%>% - qtseries(year, country, continent, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Europe"),year, country, continent, verbose = TRUE) ``` diff --git a/doc/qtseries.html b/doc/qtseries.html index 3ed3dee..6193a3b 100644 --- a/doc/qtseries.html +++ b/doc/qtseries.html @@ -319,9 +319,11 @@

qtseries

-
library(timeseries)
+
library(timeseries)
+library(gapminder)
+library(dplyr)

This is how the function qtseries works:

-

Building a time series plot with a dummy data set

+

Building a time series plot with a dummy data set:

testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3),
                        rainfall = c(rnorm(11, 100, 30), rnorm(11, 70, 10),rnorm(11, 20, 20)),
                        temp = c(rnorm(11, 70, 30), rnorm(11, 100, 10),rnorm(11, 45, 20)),
@@ -331,33 +333,20 @@ 

qtseries

#> Plotting time series...Done labelling plot!...Done applying default theme aesthetics! #> Warning: Removed 3 rows containing missing values (geom_point). #> Warning: Removed 3 row(s) containing missing values (geom_path).
-

-

Building a time series plot with the gapminder data set:

-
library(gapminder)
-library(magrittr)
-library(dplyr)
-#> 
-#> Attaching package: 'dplyr'
-#> The following objects are masked from 'package:stats':
-#> 
-#>     filter, lag
-#> The following objects are masked from 'package:base':
-#> 
-#>     intersect, setdiff, setequal, union
-gapminder %>%
-  filter(continent == "Europe")%>%
-  qtseries(year, pop, country, verbose = TRUE)
-#> Plotting time series...Done labelling plot!...Done applying default theme aesthetics!
-

Some errors you might see if qtseries is given non-numeric variables for the time or voi inputs:

-
gapminder %>%
-  filter(continent == "Europe")%>%
-  qtseries(continent, pop, country, verbose = TRUE)
-#> Error in qtseries(., continent, pop, country, verbose = TRUE): Sorry, the time variable needs to be a numeric variable!
-
-gapminder %>%
-  filter(continent == "Europe")%>%
-  qtseries(year, country, continent, verbose = TRUE)
-#> Error in qtseries(., year, country, continent, verbose = TRUE): Sorry, the variable of interest (dependent) needs to be a numeric variable!
+

+

Building a time series plot with the gapminder data set:

+
qtseries(gapminder %>%
+            filter(continent == "Europe"), year, pop, country, verbose = TRUE)
+#> Plotting time series...Done labelling plot!...Done applying default theme aesthetics!
+

+

Some errors you might see if qtseries is given non-numeric variables for the time or voi inputs:

+
qtseries(gapminder %>%
+            filter(continent == "Americas"),continent, pop, country, verbose = TRUE)
+#> Error in qtseries(gapminder %>% filter(continent == "Americas"), continent, : Sorry, the time variable needs to be a numeric variable!
+
+qtseries(gapminder %>%
+              filter(continent == "Europe"),year, country, continent, verbose = TRUE)
+#> Error in qtseries(gapminder %>% filter(continent == "Europe"), year, country, : Sorry, the variable of interest (dependent) needs to be a numeric variable!
diff --git a/tests/testthat/test-qstacktseries.R b/tests/testthat/test-qstacktseries.R new file mode 100644 index 0000000..58c667b --- /dev/null +++ b/tests/testthat/test-qstacktseries.R @@ -0,0 +1,22 @@ +test_that("Quick Stacked Area Time Series Check", { + + # create dummy dataframe + testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), + rainfall = c(runif(11, 0, 100), rnorm(11, 70, 10),rnorm(11, 20, 20)), + temp = c(rnorm(11, 70, 30), rnorm(11, 45, 20), rnorm(11, 100, 10)), + daysofsun = c(NA, NA, rnorm(9, 280, 50), rnorm(11, 300, 30), NA, rnorm(10, 340, 15)), + region = c(rep("A",11), rep("B", 11), rep("C", 11))) + + + # test that the data is grouped as expected, testing with NA's present & all arguments = TRUE + expect_match("region",as.character(rlang::get_expr(qstacktseries(testdf, year,daysofsun,region, round_values = TRUE, verbose = FALSE)$mapping$fill))) + cat(" Expected grouping & extra arguments working? -> Yes!") + + # test that the output is a ggplot object, testing without NA's present & all arguments = FALSE + expect_identical(class(qstacktseries(testdf, year,rainfall, region, default_theme = FALSE))[2], "ggplot") + cat("...Expected Object Output (ggplot)? -> Yes!") + + # test that the first layer is a geom_area layer + expect_true("GeomArea" %in% class(qstacktseries(testdf, year,temp, region)$layers[[1]]$geom)) + cat("...Expected Geom_Area Layer? -> Yes!") +}) diff --git a/tests/testthat/test-qtseries.R b/tests/testthat/test-qtseries.R index e250365..4c97b12 100644 --- a/tests/testthat/test-qtseries.R +++ b/tests/testthat/test-qtseries.R @@ -7,14 +7,14 @@ test_that("Quick Time Series Check", { region = c(rep("A",11), rep("B", 11), rep("C", 11))) # test that the data is grouped as expected, testing with NA's present & all arguments = TRUE - expect_match("state",as.character(rlang::get_expr(qtseries(testdf, year,daysofsun,state, round_values = TRUE, verbose = TRUE)$mapping$colour))) + expect_match("region",as.character(rlang::get_expr(qtseries(testdf, year,daysofsun,region, round_values = TRUE, verbose = FALSE )$mapping$colour))) cat(" Expected grouping & extra arguments working? -> Yes!") # test that the output is a ggplot object, testing without NA's present & all arguments = FALSE - expect_identical(class(qtseries(testdf, year,rainfall, state, default_theme = FALSE))[2], "ggplot") + expect_identical(class(qtseries(testdf, year,rainfall, region, default_theme = FALSE))[2], "ggplot") cat("...Expected Object Output (ggplot)? -> Yes!") # test that the first layer is a geom_point layer - expect_true("GeomPoint" %in% class(qtseries(testdf, year,temp, state)$layers[[1]]$geom)) + expect_true("GeomPoint" %in% class(qtseries(testdf, year,temp, region)$layers[[1]]$geom)) cat("...Expected Geom_Point Layer? -> Yes!") }) diff --git a/vignettes/.gitignore b/vignettes/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/vignettes/qstacktseries.Rmd b/vignettes/qstacktseries.Rmd new file mode 100644 index 0000000..c23bc21 --- /dev/null +++ b/vignettes/qstacktseries.Rmd @@ -0,0 +1,57 @@ +--- +title: "qstacktseries" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{qstacktseries} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(timeseries) +library(gapminder) +library(dplyr) +``` + +This is how the function `qstacktseries` works: + +Building a stacked area time series plot with a dummy data set: + +```{r dataset} + testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), + rainfall = c(runif(11, 0, 100), rnorm(11, 70, 10), + rnorm(11, 20, 20)), + temp = c(rnorm(11, 70, 30), rnorm(11, 45, 20), + rnorm(11, 100, 10)), + daysofsun = c(NA, NA, rnorm(9, 280, 50), rnorm(11, 300, 30), NA, + rnorm(10, 340, 15)), + region = c(rep("A",11), rep("B", 11), rep("C", 11))) +``` + +```{r example 1} +qstacktseries(testdf, year, rainfall, region, verbose = TRUE) +``` +Building a stacked area time series plot with a pre-existing data set: *gapminder* + +```{r example 2} +qstacktseries(gapminder %>% + filter(continent == "Asia"), year, gdpPercap, country, verbose = TRUE) +``` +These are some errors you might see if `qstacktseries` is given non-numeric input for the *time* or *voi* inputs: + +```{r example 3: Errors, error=TRUE} + +qstacktseries(gapminder %>% + filter(continent == "Asia"),continent, pop, country, verbose = TRUE) + +qstacktseries(gapminder %>% + filter(continent == "Africa"), year, country, continent, verbose = TRUE) +``` + diff --git a/vignettes/qtseries.Rmd b/vignettes/qtseries.Rmd index 40d8226..ca62a3e 100644 --- a/vignettes/qtseries.Rmd +++ b/vignettes/qtseries.Rmd @@ -16,11 +16,13 @@ knitr::opts_chunk$set( ```{r setup} library(timeseries) +library(gapminder) +library(dplyr) ``` This is how the function `qtseries` works: -Building a time series plot with a dummy data set +Building a time series plot with a dummy data set: ```{r dummy dataset setup} testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), @@ -34,24 +36,19 @@ testdf <- data.frame(year = rep(seq(from = 1980, to= 1990, 1), 3), qtseries(testdf, year, daysofsun, region, verbose = TRUE) ``` -Building a time series plot with the gapminder data set: +Building a time series plot with the *gapminder* data set: ```{r example 2} -library(gapminder) -library(magrittr) -library(dplyr) -gapminder %>% - filter(continent == "Europe")%>% - qtseries(year, pop, country, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Europe"), year, pop, country, verbose = TRUE) ``` + Some errors you might see if `qtseries` is given non-numeric variables for the *time* or *voi* inputs: ```{r example 3: Errors, error=TRUE} -gapminder %>% - filter(continent == "Europe")%>% - qtseries(continent, pop, country, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Americas"),continent, pop, country, verbose = TRUE) -gapminder %>% - filter(continent == "Europe")%>% - qtseries(year, country, continent, verbose = TRUE) +qtseries(gapminder %>% + filter(continent == "Europe"),year, country, continent, verbose = TRUE) ```