@@ -28,7 +28,7 @@ test_that("graticule lines can be removed via theme", {
2828 expect_doppelganger(" no panel grid" , plot )
2929})
3030
31- test_that(" axis labels can be set manually " , {
31+ test_that(" axis labels are correct for manual breaks " , {
3232 skip_if_not_installed(" sf" )
3333
3434 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", {
4949 graticule [graticule $ type == " N" , ]$ degree_label ,
5050 c(" 1000" , " 1500" , " 2000" )
5151 )
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()
5259
5360 # character labels
5461 b <- ggplot_build(
@@ -71,9 +78,14 @@ test_that("axis labels can be set manually", {
7178 graticule [graticule $ type == " N" , ]$ degree_label ,
7279 c(" D" , " E" , " F" )
7380 )
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()
7488
75- # factors are treated like character labels
76- # and are not parsed
7789 b <- ggplot_build(
7890 plot +
7991 scale_x_continuous(
@@ -94,9 +106,14 @@ test_that("axis labels can be set manually", {
94106 graticule [graticule $ type == " N" , ]$ degree_label ,
95107 c(" 1 * degree * N" , " 1.5 * degree * N" , " 2 * degree * N" )
96108 )
109+ })
97110
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()
98116
99- # expressions mixed with character labels
100117 b <- ggplot_build(
101118 plot +
102119 scale_x_continuous(
@@ -143,33 +160,32 @@ test_that("axis labels can be set manually", {
143160 graticule [graticule $ type == " E" , ]$ degree_label ,
144161 parsed
145162 )
163+ })
164+
165+ test_that(" degree labels are automatically parsed" , {
166+ skip_if_not_installed(" sf" )
146167
147- # autoparsing of degree labels
148168 data <- sf :: st_sfc(
149169 sf :: st_polygon(list (matrix (1e1 * c(1 , 2 , 3 , 1 , 1 , 3 , 2 , 1 ), ncol = 2 ))),
150170 crs = 4326 # basic long-lat crs
151171 )
152-
153172 plot <- ggplot(data ) + geom_sf()
154-
155173 b <- ggplot_build(
156174 plot +
157175 scale_x_continuous(breaks = c(10 , 20 , 30 )) +
158176 scale_y_continuous(breaks = c(10 , 15 , 20 ))
159177 )
178+
160179 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 )
166183 )
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 )
171187 )
172-
188+ expect_true(all(vapply( graticule $ degree_label , is.language , logical ( 1 ))))
173189})
174190
175191test_that(" Inf is squished to range" , {
0 commit comments