Skip to content

Commit

Permalink
Style file
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasKnecht committed Oct 1, 2019
1 parent 02a038e commit daeb34e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion R/position-nudgestack.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' ESM <- tsbox::ts_tbl(EuStockMarkets)
#'
#' ESM_prep <- ESM %>%
#' dplyr::mutate(time = as.Date(paste0(format(time, "%Y-%m"),"-1"))) %>%
#' dplyr::mutate(time = as.Date(paste0(format(time, "%Y-%m"), "-1"))) %>%
#' group_by(id, time) %>%
#' summarize(value = mean(value)) %>%
#' filter(time >= "1995-01-01" & time < "1998-01-01")
Expand Down
2 changes: 1 addition & 1 deletion man/position_nudgestack.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions tests/testthat/test-position-nudgestack.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
context("position_nudgestack")

test_that("position_nudgestack draws correctly", {

ESM <- tsbox::ts_tbl(EuStockMarkets)

ESM_prep <- ESM %>%
dplyr::mutate(time = as.Date(paste0(format(time, "%Y-%m"),"-1"))) %>%
dplyr::mutate(time = as.Date(paste0(format(time, "%Y-%m"), "-1"))) %>%
dplyr::group_by(id, time) %>%
dplyr::summarize(value = mean(value)) %>%
dplyr::filter(time >= "1995-01-01" & time < "1998-01-01")

stock_marked <- ggplot(data = ESM_prep, mapping = aes(x = time, y = value, fill = id)) +
stock_marked <- ggplot(
data = ESM_prep,
mapping = aes(x = time, y = value, fill = id)
) +
geom_col(position = position_nudgestack(x = 15))

expect_doppelganger(
Expand All @@ -35,18 +37,17 @@ test_that("nudging works in both dimensions simultaneously", {
expect_equal(data$xmin, 1.05:3.05)
expect_equal(data$xmax, 1.95:3.95)
expect_equal(data$y, 3:5)
expect_equal(data$ymin, c(2,2,2))
expect_equal(data$ymin, c(2, 2, 2))
expect_equal(data$ymax, 3:5)

})

test_that("nudging works for discrete values correctly", {
set.seed(111)

# x nudge value for discrete data
series <- data_frame(
time = factor(c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4))),
type = rep(c('a', 'b', 'c', 'd'), 4),
time = factor(c(rep(1, 4), rep(2, 4), rep(3, 4), rep(4, 4))),
type = rep(c("a", "b", "c", "d"), 4),
value = rpois(16, 10)
)

Expand All @@ -56,10 +57,9 @@ test_that("nudging works for discrete values correctly", {

data <- layer_data(p)

expect_equal(data$x, c(rep(1.5, 4),rep(2.5, 4), rep(3.5, 4), rep(4.5, 4)))
expect_equal(data$xmin, c(rep(1.5, 4),rep(2.5, 4), rep(3.5, 4), rep(4.5, 4)))
expect_equal(data$xmax, c(rep(1.5, 4),rep(2.5, 4), rep(3.5, 4), rep(4.5, 4)))

expect_equal(data$x, c(rep(1.5, 4), rep(2.5, 4), rep(3.5, 4), rep(4.5, 4)))
expect_equal(data$xmin, c(rep(1.5, 4), rep(2.5, 4), rep(3.5, 4), rep(4.5, 4)))
expect_equal(data$xmax, c(rep(1.5, 4), rep(2.5, 4), rep(3.5, 4), rep(4.5, 4)))
})


Expand All @@ -78,9 +78,9 @@ test_that("data is sorted prior to stacking", {

test_that("negative and positive values are handled separately", {
df <- data_frame(
x = c(1,1,1,2,2),
g = c(1,2,3,1,2),
y = c(1,-1,1,2,-3)
x = c(1, 1, 1, 2, 2),
g = c(1, 2, 3, 1, 2),
y = c(1, -1, 1, 2, -3)
)
p <- ggplot(df, aes(x, y, fill = factor(g))) +
geom_col(position = position_nudgestack(x = 0.5))
Expand Down Expand Up @@ -110,4 +110,3 @@ test_that("position_nudgestack() can stack correctly when ymax is NA", {
geom_point(position = position_nudgestack(x = 0.5))
expect_equal(layer_data(p)$y, c(1, 2))
})

0 comments on commit daeb34e

Please sign in to comment.