-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from MattCowgill/dev
v0.3.1
- Loading branch information
Showing
9 changed files
with
119 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
Package: grattantheme | ||
Type: Package | ||
Title: Create Graphs In The Grattan Institute Style | ||
Version: 0.3.0.900 | ||
Title: Create Graphs in the Grattan Institute Style | ||
Version: 0.3.1 | ||
Authors@R: c( | ||
person("Matt", "Cowgill", email = "[email protected]", | ||
role = c("aut", "cre")), | ||
person("Will", "Mackey", email = "[email protected]", | ||
role = "aut")) | ||
Description: This package enables the user to create ggplot2 charts that conform | ||
Description: Enables the user to create ggplot2 charts that conform | ||
to the Grattan Institute style guide. | ||
License: GPL-3 | ||
Depends: R (>= 3.1) | ||
|
@@ -27,5 +27,5 @@ Encoding: UTF-8 | |
LazyData: true | ||
RoxygenNote: 6.1.1 | ||
Suggests: | ||
testthat, | ||
testthat (>= 2.1.0), | ||
covr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
context("Check that theme_grattan() and associated functions work") | ||
|
||
# Create base object to use for test | ||
base_plot <- ggplot(mtcars, aes(x = mpg, y = hp)) + | ||
geom_point() | ||
|
||
p <- base_plot + theme_grattan() | ||
|
||
test_that("theme_grattan() is a theme obkect", { | ||
expect_is(theme_grattan(), "theme") | ||
}) | ||
|
||
test_that("plot with theme_grattan() is a ggplot2 object",{ | ||
expect_is(p, "gg") | ||
}) | ||
|
||
test_that("theme conforms with style guide in key ways",{ | ||
expect_equal(p$theme$text$size, 18) | ||
|
||
expect_equal(p$theme$line$colour, "#C3C7CB") | ||
|
||
expect_equal(p$theme$rect$fill, "white") | ||
|
||
}) | ||
|
||
test_that("theme_grattan() arguments work",{ | ||
p_flipped <- base_plot + theme_grattan(flipped = TRUE) | ||
|
||
expect_equal(attr(p_flipped$theme$panel.grid.major.x, "class")[1], "element_line") | ||
|
||
p_orange <- base_plot + theme_grattan(background = "orange") | ||
|
||
expect_equal(p_orange$theme$rect$fill, "#FEF0DE") | ||
|
||
expect_equal(p$theme$legend.position, "none") | ||
|
||
p_legend <- base_plot + theme_grattan(legend = "top") | ||
|
||
expect_equal(p_legend$theme$legend.position, "top") | ||
|
||
}) | ||
|
||
test_that("grattan colour functions work as expected", { | ||
|
||
expect_length(grattan_pal(), 5) | ||
|
||
expect_length(grattan_pal(n = 2), 2) | ||
|
||
expect_length(grattan_pal(n = 10), 10) | ||
|
||
expect_warning(grattan_pal(n = 10)) | ||
|
||
expect_error(grattan_pal(n = 11)) | ||
|
||
plot_w_col <- base_plot + | ||
geom_point(aes(col = factor(cyl))) + | ||
grattan_colour_manual(n = 3) | ||
|
||
expect_is(plot_w_col, "gg") | ||
|
||
plot_w_col_built <- ggplot_build(plot_w_col) | ||
|
||
expect_equal(length(unique(plot_w_col_built$data[[2]]$colour)), 3) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,44 @@ | ||
context("Powerpoint slide creation") | ||
|
||
library(grattantheme) | ||
library(ggplot2) | ||
|
||
# Create base object to use for test | ||
base_plot <- ggplot(mtcars, aes(x = mpg, y = hp)) + | ||
geom_point() | ||
|
||
p <- base_plot + theme_grattan() | ||
|
||
p_labs <- p + labs(title = "Title", subtitle = "Subtitle", caption = "Notes: Source:") | ||
|
||
p_labs_2 <- p_labs + labs(title = "This is my second slide") | ||
|
||
plot_list <- list(p_labs, p_labs_2) | ||
|
||
# Tests | ||
test_that("theme_grattan() creates ggplot2 object",{ | ||
expect_is(p, "gg") | ||
}) | ||
|
||
test_that("make_slide() saves .pptx object",{ | ||
|
||
p_labs <- p + labs(title = "Title", subtitle = "Subtitle", caption = "Notes: Source:") | ||
skip_if_not(pandoc_version() >= 2.1) | ||
|
||
make_slide(graph = p_labs, filename = "testslide.pptx") | ||
|
||
expect_that(file.exists("./testslide.pptx"), equals(TRUE)) | ||
expect_true(file.exists("./testslide.pptx")) | ||
|
||
file.remove("./testslide.pptx") | ||
|
||
}) | ||
|
||
test_that("make_presentation() saves .pptx object",{ | ||
|
||
skip_if_not(pandoc_version() >= 2.1) | ||
|
||
make_presentation(plot_list, filename = "testpresentation.pptx", | ||
title = "Test presentation", subtitle = "Subtitle") | ||
|
||
expect_true(file.exists("./testpresentation.pptx")) | ||
|
||
file.remove("./testpresentation.pptx") | ||
|
||
}) | ||
|