-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest-misc.R
More file actions
131 lines (116 loc) · 3.35 KB
/
test-misc.R
File metadata and controls
131 lines (116 loc) · 3.35 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
source("helpers.R")
using("tinysnapshot")
# empty plot(s)
f = function() {
tinyplot(Sepal.Length ~ Petal.Length, data = iris, type = "n")
}
expect_snapshot_plot(f, label = "type_n")
f = function() {
tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "n")
}
expect_snapshot_plot(f, label = "type_n_by")
f = function() {
tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "l", empty = TRUE)
}
expect_snapshot_plot(f, label = "type_l_empty")
# jittered points
f = function() {
set.seed(42)
tinyplot(Temp ~ Month | ordered(Month), airquality, type = "j", pch = 16)
}
expect_snapshot_plot(f, label = "type_j")
f = function() {
set.seed(42)
tinyplot(Species ~ Sepal.Length, data = iris, type = "j")
}
expect_snapshot_plot(f, label = "type_j_y")
# log axes
f = function() {
op = tpar(mfrow = c(1, 2))
plot(Temp ~ Day, data = airquality, log = "x")
tinyplot(Temp ~ Day, data = airquality, log = "x")
tpar(op)
}
expect_snapshot_plot(f, label = "arg_log_x")
f = function() {
op = tpar(mfrow = c(1, 2))
plot(Temp ~ Day, data = airquality, log = "y")
tinyplot(Temp ~ Day, data = airquality, log = "y")
tpar(op)
}
expect_snapshot_plot(f, label = "arg_log_y")
f = function() {
op = tpar(mfrow = c(1, 2))
plot(Temp ~ Day, data = airquality, log = "xy")
tinyplot(Temp ~ Day, data = airquality, log = "xy")
tpar(op)
}
expect_snapshot_plot(f, label = "arg_log_xy")
f = function() {
op = tpar(mfrow = c(1, 2))
plot(Temp ~ Day, data = airquality, log = "yx")
tinyplot(Temp ~ Day, data = airquality, log = "yx")
tpar(op)
}
expect_snapshot_plot(f, label = "arg_log_yx")
f = function() {
op = tpar(mfrow = c(1, 1))
m = transform(mtcars, cyl = factor(cyl))
pred = predict(lm(mpg ~ wt + cyl, m), interval = "confidence")
m = cbind(m, pred)
with(
m,
tinyplot(wt, fit, ymin = lwr, ymax = upr, by = cyl, type = "ribbon", grid = TRUE)
)
with(
m,
tinyplot(wt, mpg, by = cyl, pch = 16, add = TRUE)
)
tpar(op)
}
expect_snapshot_plot(f, label = "addTRUE")
# formatting axis tick labels
f = function() {
plt(
I(decrease / 100) ~ treatment,
data = OrchardSprays,
xaxl = tolower, yaxl = "percent"
)
}
expect_snapshot_plot(f, label = "xaxl_yaxl")
# formatting axis breaks and tick labels at the same time
f = function() {
plt(
I(decrease / 100) ~ treatment,
data = OrchardSprays,
xaxb = c("A", "C", "E", "G"), xaxl = tolower,
yaxb = c(0, 0.2, 0.5, 1, 1.4), yaxl = "percent",
grid = TRUE
)
}
expect_snapshot_plot(f, label = "xaxb_yaxb_xaxl_yaxl")
# saving files (here: png)
if (requireNamespace("png", quietly = TRUE)) {
f = function() {
tmp_path = tempfile(fileext = ".png")
suppressWarnings(tinyplot(
Sepal.Length ~ Petal.Length,
data = iris,
file = tmp_path, width = 4, height = 4
))
obj = png::readPNG(tmp_path, info = TRUE)
unlink(tmp_path)
# dims = attr(obj, "dim")
dims = attr(obj, "info")[["dim"]]
return(dims)
}
# expect_equal(f(), c(1200, 1200, 4), label = "png_size")
expect_equal(f(), c(1200, 1200), label = "png_size")
}
# Issue #545: Restore xaxs and yaxs par settings when modified internally
f = function() {
par(mfrow = c(1, 2))
tinyplot(~species, data = penguins, type = type_barplot())
tinyplot(1:10, pch = 19, cex = 2, main = "dots not cut off")
}
expect_snapshot_plot(f, label = "issue_545_xaxs_yaxs_restoration")