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