Skip to content

Commit b06560c

Browse files
committed
doc
1 parent a7379fc commit b06560c

File tree

6 files changed

+96
-29
lines changed

6 files changed

+96
-29
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type: Package
22
Package: dint
33
Title: A Toolkit for Year-Quarter, Year-Month and Year-Isoweek
44
Dates
5-
Version: 2.0.0.9005
5+
Version: 2.0.0.9006
66
Authors@R:
77
person(given = "Stefan",
88
family = "Fleck",

R/scale_date_xx.R

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
#'
1010
#'
1111
#' @inheritParams ggplot2::scale_x_date
12-
#' @seealso [date_xx_breaks]
12+
#' @param labels One of:
13+
#' * `NULL` for no labels
14+
#' * `ggplot2::waiver()` for the default labels computed by the
15+
#' transformation object
16+
#' * A `character` vector giving labels (must be same length as `breaks`, so
17+
#' it's a good idea to specify manual breaks if you use manual labels)
18+
#' * A function that takes the breaks as input and returns labels as output
19+
#' @param breaks One of:
20+
#' * `NULL` for no breaks
21+
#' * `ggplot2::waiver()` for automatic breaks (see [date_xx_breaks()])
22+
#' * A `date_xx` vector of breaks
23+
#' * A function that takes the limits as input and returns breaks as output
1324
#'
1425
#' @name scale_date_xx
1526
#' @include zoo-compat.R
@@ -19,15 +30,33 @@
1930
#'
2031
#' @examples
2132
#' if (require("ggplot2", quietly = TRUE)){
22-
#' dd <- data.frame(date = seq(date_yq(2016, 1), date_yq(2018, 1)), V1 = 1:9)
23-
#' p <- ggplot(dd, aes(x = date, y = V1)) +
24-
#' geom_point()
2533
#'
26-
#' p # automatically uses the proper scale
27-
#' p + scale_x_date_yq("quarters with default spacing")
28-
#' p + scale_x_date_yq(breaks = date_yq_breaks(3))
29-
#' }
34+
#' dd <- data.frame(date = seq(date_yq(2016, 1), date_yq(2018, 1)), V1 = 1:9)
35+
#' p <- ggplot(dd, aes(x = date, y = V1)) +
36+
#' geom_point()
37+
#'
38+
#' p # automatically uses the proper scale
39+
#' p + scale_x_date_yq("quarters with default spacing")
40+
#' p + scale_x_date_yq(breaks = date_yq_breaks(3))
41+
#'
3042
#'
43+
#' # Different ways to specify breaks and labels
44+
#' p <- ggplot(
45+
#' data.frame(date = seq(date_yq(2012, 4), date_yq(2018, 4)), V1 = 1:25),
46+
#' aes(x = date, y = V1)
47+
#' ) +
48+
#' geom_point()
49+
#'
50+
#' p + scale_x_date_yq(labels = waiver()) + ggtitle("auto Labels")
51+
#' p + scale_x_date_yq(labels = NULL) + ggtitle("no Labels")
52+
#' p + scale_x_date_yq(labels = LETTERS[1:4]) + ggtitle("manual Labels")
53+
#' p + scale_x_date_yq(labels = format_yq_iso) + ggtitle("function Labels")
54+
#'
55+
#' p + scale_x_date_yq(breaks = waiver()) + ggtitle("auto breaks")
56+
#' p + scale_x_date_yq(breaks = NULL) + ggtitle("no breaks")
57+
#' p + scale_x_date_yq(breaks = date_yq(2013, 2:3) ) + ggtitle("manual breaks")
58+
#' p + scale_x_date_yq(breaks = date_yq_breaks(1) ) + ggtitle("function breaks")
59+
#' }
3160
NULL
3261

3362

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ S3 classes and methods to create and work with year-quarter and year-month
2525
vectors. Basic arithmetic operations (such as adding and subtracting) are
2626
supported, as well as formatting and converting to and from standard R
2727
Date types. For more info please refer to the
28-
[package vignette](https://cran.r-project.org/web/packages/dint/vignettes/dint.html)
28+
[package vignette](https://CRAN.R-project.org/package=dint/vignettes/dint.html)
2929

3030

3131
## Dependencies

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dint
77

88
A Toolkit for Year-Quarter, Year-Month and Year-Isoweek Dates
99

10-
S3 classes and methods to create and work with year-quarter and year-month vectors. Basic arithmetic operations (such as adding and subtracting) are supported, as well as formatting and converting to and from standard R Date types. For more info please refer to the [package vignette](https://cran.r-project.org/web/packages/dint/vignettes/dint.html)
10+
S3 classes and methods to create and work with year-quarter and year-month vectors. Basic arithmetic operations (such as adding and subtracting) are supported, as well as formatting and converting to and from standard R Date types. For more info please refer to the [package vignette](https://CRAN.R-project.org/package=dint/vignettes/dint.html)
1111

1212
Dependencies
1313
------------

man/scale_date_xx.Rd

Lines changed: 30 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/manual_tests/ggplot_scales.Rmd

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ ggplot(
3030
scale_x_date_yq(breaks = date_yq_breaks(3))
3131
3232
33-
34-
3533
ggplot(
3634
dd[get_year(dd$date) %in% 2014, ],
3735
aes(
@@ -42,7 +40,6 @@ ggplot(
4240
geom_point() +
4341
scale_x_date_yq()
4442
45-
4643
```
4744

4845

@@ -75,6 +72,32 @@ ggplot(
7572
```
7673

7774

75+
## scale arguments
76+
77+
```{r}
78+
79+
p <- ggplot(
80+
dd,
81+
aes(
82+
x = date,
83+
y = V1
84+
)
85+
) +
86+
geom_point()
87+
88+
p + scale_x_date_yq(labels = waiver()) + ggtitle("auto Labels")
89+
p + scale_x_date_yq(labels = NULL) + ggtitle("no Labels")
90+
p + scale_x_date_yq(breaks = date_yq(2016, 2:3), labels = LETTERS[1:2] ) + ggtitle("manual Labels")
91+
p + scale_x_date_yq(labels = format_yq_iso) + ggtitle("function Labels")
92+
93+
p + scale_x_date_yq(breaks = waiver()) + ggtitle("auto breaks")
94+
p + scale_x_date_yq(breaks = NULL) + ggtitle("no breaks")
95+
p + scale_x_date_yq(breaks = date_yq(2016, 2:3) ) + ggtitle("manual breaks")
96+
p + scale_x_date_yq(breaks = date_yq_breaks(1) ) + ggtitle("function breaks")
97+
98+
99+
100+
```
78101
## Print every second quarter
79102

80103
```{r}

0 commit comments

Comments
 (0)