forked from plotly/plotly.R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ggplot-ylim.R
More file actions
35 lines (29 loc) · 1.07 KB
/
test-ggplot-ylim.R
File metadata and controls
35 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
context("ggplot ylim")
# http://www.cookbook-r.com/Graphs/Bar_and_line_graphs_%28ggplot2%29/
df <- data.frame(time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23))
gg.ylim <-
ggplot(data=df, aes(x=time, y=total_bill, group=1)) +
geom_line() +
geom_point() +
ylim(0, max(df$total_bill)) +
xlab("Time of day") + ylab("Total bill") +
ggtitle("Average bill for 2 people")
expect_traces <- function(gg, n.traces, name){
stopifnot(is.ggplot(gg))
stopifnot(is.numeric(n.traces))
L <- save_outputs(gg, paste0("ylim-", name))
all.traces <- L$data
no.data <- sapply(all.traces, function(tr) {
is.null(tr[["x"]]) && is.null(tr[["y"]])
})
has.data <- all.traces[!no.data]
expect_equal(length(has.data), n.traces)
list(traces=has.data, layout=L$layout)
}
test_that("ylim is respected for 1 trace", {
info <- expect_traces(gg.ylim, 1, "one-trace")
expected.ylim <- c(0, max(df$total_bill))
expect_equal(info$layout$yaxis$range, expected.ylim)
expect_identical(info$traces[[1]]$showlegend, FALSE)
})