@@ -32,7 +32,7 @@ test_that("graticule lines can be removed via theme", {
32
32
expect_doppelganger(" no panel grid" , plot )
33
33
})
34
34
35
- test_that(" axis labels can be set manually " , {
35
+ test_that(" axis labels are correct for manual breaks " , {
36
36
skip_if_not_installed(" sf" )
37
37
38
38
plot <- ggplot(sf :: st_polygon(list (matrix (1e3 * c(1 , 2 , 3 , 1 , 1 , 3 , 2 , 1 ), ncol = 2 )))) +
@@ -53,6 +53,13 @@ test_that("axis labels can be set manually", {
53
53
graticule [graticule $ type == " N" , ]$ degree_label ,
54
54
c(" 1000" , " 1500" , " 2000" )
55
55
)
56
+ })
57
+
58
+ test_that(" axis labels can be set manually" , {
59
+ skip_if_not_installed(" sf" )
60
+
61
+ plot <- ggplot(sf :: st_polygon(list (matrix (1e3 * c(1 , 2 , 3 , 1 , 1 , 3 , 2 , 1 ), ncol = 2 )))) +
62
+ geom_sf()
56
63
57
64
# character labels
58
65
b <- ggplot_build(
@@ -75,9 +82,14 @@ test_that("axis labels can be set manually", {
75
82
graticule [graticule $ type == " N" , ]$ degree_label ,
76
83
c(" D" , " E" , " F" )
77
84
)
85
+ })
86
+
87
+ test_that(" factors are treated like character labels and are not parsed" , {
88
+ skip_if_not_installed(" sf" )
89
+
90
+ plot <- ggplot(sf :: st_polygon(list (matrix (1e3 * c(1 , 2 , 3 , 1 , 1 , 3 , 2 , 1 ), ncol = 2 )))) +
91
+ geom_sf()
78
92
79
- # factors are treated like character labels
80
- # and are not parsed
81
93
b <- ggplot_build(
82
94
plot +
83
95
scale_x_continuous(
@@ -98,9 +110,14 @@ test_that("axis labels can be set manually", {
98
110
graticule [graticule $ type == " N" , ]$ degree_label ,
99
111
c(" 1 * degree * N" , " 1.5 * degree * N" , " 2 * degree * N" )
100
112
)
113
+ })
101
114
115
+ test_that(" expressions can be mixed with character labels" , {
116
+ skip_if_not_installed(" sf" )
117
+
118
+ plot <- ggplot(sf :: st_polygon(list (matrix (1e3 * c(1 , 2 , 3 , 1 , 1 , 3 , 2 , 1 ), ncol = 2 )))) +
119
+ geom_sf()
102
120
103
- # expressions mixed with character labels
104
121
b <- ggplot_build(
105
122
plot +
106
123
scale_x_continuous(
@@ -147,33 +164,32 @@ test_that("axis labels can be set manually", {
147
164
graticule [graticule $ type == " E" , ]$ degree_label ,
148
165
parsed
149
166
)
167
+ })
168
+
169
+ test_that(" degree labels are automatically parsed" , {
170
+ skip_if_not_installed(" sf" )
150
171
151
- # autoparsing of degree labels
152
172
data <- sf :: st_sfc(
153
173
sf :: st_polygon(list (matrix (1e1 * c(1 , 2 , 3 , 1 , 1 , 3 , 2 , 1 ), ncol = 2 ))),
154
174
crs = 4326 # basic long-lat crs
155
175
)
156
-
157
176
plot <- ggplot(data ) + geom_sf()
158
-
159
177
b <- ggplot_build(
160
178
plot +
161
179
scale_x_continuous(breaks = c(10 , 20 , 30 )) +
162
180
scale_y_continuous(breaks = c(10 , 15 , 20 ))
163
181
)
182
+
164
183
graticule <- b $ layout $ panel_params [[1 ]]$ graticule
165
- parsed <- vector(" list" , 3 )
166
- parsed [1 : 3 ] <- parse(text = c(" 10*degree*E" , " 20*degree*E" , " 30*degree*E" ))
167
- expect_identical(
168
- graticule [graticule $ type == " E" , ]$ degree_label ,
169
- parsed
184
+ expect_setequal(
185
+ graticule [graticule $ type == " N" , ]$ degree ,
186
+ c(10 , 15 , 20 )
170
187
)
171
- parsed [1 : 3 ] <- parse(text = c(" 10*degree*N" , " 15*degree*N" , " 20*degree*N" ))
172
- expect_identical(
173
- graticule [graticule $ type == " N" , ]$ degree_label ,
174
- parsed
188
+ expect_setequal(
189
+ graticule [graticule $ type == " E" , ]$ degree ,
190
+ c(10 , 20 , 30 )
175
191
)
176
-
192
+ expect_true(all(vapply( graticule $ degree_label , is.language , logical ( 1 ))))
177
193
})
178
194
179
195
test_that(" Inf is squished to range" , {
0 commit comments