9
9
# ' It allows more flexibility for users to visualise the data in various ways.
10
10
# '
11
11
# ' @param data A data frame or a grouped data frame including a `Date` variable.
12
- # ' @param x A variable mapping to time of day. If integer 1 is specified, it
13
- # ' simply returns calendar grids on x without transformation.
14
- # ' @param y One variable or more mapping to value . If more than one variable,
12
+ # ' @param x A variable mapping to x axis, for example time of day. If integer 1
13
+ # ' is specified, it simply returns calendar grids on x without transformation.
14
+ # ' @param y One variable or more mapping to y axis . If more than one variable,
15
15
# ' the variables needs to be quoted. If integer 1 is specified, it returns
16
16
# ' calendar grids on y without transformation.
17
17
# ' @param date A `Date` variable mapping to dates in the calendar.
71
71
# ' x = Time, y = Hourly_Counts, date = Date, sunday = TRUE
72
72
# ' )
73
73
# '
74
- # ' p2 <- grped_calendar %>%
74
+ # ' grped_calendar %>%
75
75
# ' ggplot(aes(x = .Time, y = .Hourly_Counts, group = Date)) +
76
76
# ' geom_line() +
77
77
# ' facet_wrap(~ Sensor_Name, nrow = 2)
78
- # ' # prettify(p2, label = "text" ) not working for group_by
78
+ # ' # prettify() not working for group_by
79
79
# '
80
80
# ' @export
81
81
frame_calendar <- function (
@@ -164,7 +164,7 @@ frame_calendar_ <- function(
164
164
# but quo_name() doesn't support LHS
165
165
data <- cal_grids %> %
166
166
right_join(data , by = c(" PANEL" = quo_name(date ))) %> %
167
- mutate(!! .date : = PANEL )
167
+ dplyr :: mutate(!! .date : = PANEL )
168
168
169
169
# Define a small multiple width and height
170
170
width <- resolution(data $ .gx , zero = FALSE ) * 0.95
@@ -173,28 +173,28 @@ frame_calendar_ <- function(
173
173
174
174
if (calendar == " monthly" ) {
175
175
data <- data %> %
176
- group_by(MPANEL ) %> %
177
- mutate(
176
+ dplyr :: group_by(MPANEL ) %> %
177
+ dplyr :: mutate(
178
178
.gx = .gx + MCOL * margins ,
179
179
.gy = .gy - MROW * margins
180
180
)
181
181
}
182
182
183
183
data <- ungroup(data ) # is.null(scale)
184
184
if (scale == " free" ) {
185
- data <- group_by(data , ROW , COL )
185
+ data <- dplyr :: group_by(data , ROW , COL )
186
186
} else if (scale == " free_wday" ) {
187
187
data <- data %> %
188
- mutate(.day = wday(!! date )) %> %
189
- group_by(.day )
188
+ dplyr :: mutate(.day = wday(!! date )) %> %
189
+ dplyr :: group_by(.day )
190
190
} else if (scale == " free_mday" ) {
191
191
data <- data %> %
192
- mutate(.day = mday(!! date )) %> %
193
- group_by(.day )
192
+ dplyr :: mutate(.day = mday(!! date )) %> %
193
+ dplyr :: group_by(.day )
194
194
}
195
195
196
196
data <- data %> %
197
- mutate(
197
+ dplyr :: mutate(
198
198
.ymax = max(!!! y , na.rm = TRUE ),
199
199
.ymin = min(!!! y , na.rm = TRUE )
200
200
)
@@ -204,30 +204,30 @@ frame_calendar_ <- function(
204
204
}
205
205
.y <- paste0(" ." , y [[1 ]])
206
206
data <- data %> %
207
- mutate(
207
+ dplyr :: mutate(
208
208
theta = 2 * pi * normalise(!! x , xmax = max_na(!! x )),
209
209
radius = normalise(!!! y , xmax = max_na(!!! y )),
210
210
!! .x : = .gx + width * radius * sin(theta ),
211
211
!! .y : = .gy + height * radius * cos(theta )
212
212
) %> %
213
- select(- c(theta , radius ))
213
+ dplyr :: select(- c(theta , radius ))
214
214
} else {
215
215
fn <- function (x , ymax , ymin ) { # temporal function for mutate at
216
216
normalise(x , xmax = max_na(ymax ), xmin = min_na(ymin )) * height
217
217
}
218
218
if (possibly_identity(x )) {
219
- data <- mutate(data , .x = .gx )
219
+ data <- dplyr :: mutate(data , .x = .gx )
220
220
} else {
221
221
data <- data %> %
222
- mutate(
222
+ dplyr :: mutate(
223
223
!! .x : = .gx + normalise(!! x , xmax = max_na(!! x )) * width
224
224
)
225
225
}
226
226
if (possibly_identity(y )) {
227
- data <- mutate(data , .y = .gy )
227
+ data <- dplyr :: mutate(data , .y = .gy )
228
228
} else {
229
229
data <- data %> %
230
- mutate_at(
230
+ dplyr :: mutate_at(
231
231
.vars = vars(!!! y ),
232
232
.funs = funs(zzz = .gy + fn(. , .ymax , .ymin ))
233
233
)
@@ -242,10 +242,10 @@ frame_calendar_ <- function(
242
242
243
243
data <- data %> %
244
244
ungroup() %> %
245
- select(- (ROW : .gy )) %> %
246
- select(- c(.ymax , .ymin ))
245
+ dplyr :: select(- (ROW : .gy )) %> %
246
+ dplyr :: select(- c(.ymax , .ymin ))
247
247
if (scale %in% c(" free_wday" , " free_mday" )) {
248
- data <- select(data , - .day ) # remove .day variable
248
+ data <- dplyr :: select(data , - .day ) # remove .day variable
249
249
}
250
250
251
251
# rename y's variables
0 commit comments