Skip to content

Commit

Permalink
Need to round before indexing month (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmoore authored and angusmoore committed Aug 19, 2019
1 parent 6c81f65 commit 5d1ef47
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ treated as dates ([#356](https://github.com/angusmoore/arphit/pull/356))
* Fixed autolabeller failure when have to identical column series ([#324](https://github.com/angusmoore/arphit/pull/324))
* Underscores in titles no longer throw errors for unknown width ([#337](https://github.com/angusmoore/arphit/pull/337))
* Better vertical spacing of footnotes, sources, and axis labels ([#342](https://github.com/angusmoore/arphit/pull/342))
* Correct month labels with high-resolution (e.g. hourly) data; previously showed one month offset
([#383](https://github.com/angusmoore/arphit/pull/383))

## Deprecated or removed

Expand Down
2 changes: 1 addition & 1 deletion R/axes.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ xlabels.ts_month <- function(xlim) {

# convert the labels to month letters
months <- seq(from = 1 + (startmonth-floor(startmonth)) * 12, length.out = length(ticks))
labels <- substr(month.abb[1 + (months - 1) %% 12], 1, 1)
labels <- substr(month.abb[round(1 + (months - 1) %% 12)], 1, 1)
at <- ticks + 0.5 * 1/12

# add years
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tests/testthat/test-axes.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ test_that("Miscellaneous x axis tests", {
)
})

# incorrect rounding for months with hourly data (#381)
test_that("months with hourly data", {
set.seed(42)
data <- tibble(
date = seq(lubridate::parse_date_time('2014-02-01 00:00', 'Ymd HM'),
by = '1 hour',
length.out = 1000),
value = cumsum(rnorm(1000))
)
p <- data %>%
arphitgg(agg_aes(x=date, y=value)) +
agg_line()
expect_true(check_graph(p, "axes-month-hourly-data-381"))
})

## Unit handling ===============
test_that("Units", {
p <- arphitgg() + agg_units("foo")
Expand Down

0 comments on commit 5d1ef47

Please sign in to comment.