@@ -86,3 +86,32 @@ test_that("annotate() warns about `stat` or `position` arguments", {
8686 annotate(" point" , 1 : 3 , 1 : 3 , stat = " density" , position = " dodge" )
8787 )
8888})
89+
90+ test_that(" annotation_custom() and annotation_raster() adhere to scale transforms" , {
91+ rast <- matrix (rainbow(10 ), nrow = 1 )
92+
93+ p <- ggplot() +
94+ annotation_raster(rast , 1 , 10 , 1 , 9 ) +
95+ scale_x_continuous(transform = " log10" , limits = c(0.1 , 100 ), expand = FALSE ) +
96+ scale_y_continuous(limits = c(0 , 10 ), expand = FALSE )
97+ ann <- get_layer_grob(p )[[1 ]]
98+
99+ expect_equal(as.numeric(ann $ x ), 1 / 3 )
100+ expect_equal(as.numeric(ann $ y ), 1 / 10 )
101+ expect_equal(as.numeric(ann $ width ), 1 / 3 )
102+ expect_equal(as.numeric(ann $ height ), 8 / 10 )
103+
104+ rast <- rasterGrob(rast , width = 1 , height = 1 )
105+
106+ p <- ggplot() +
107+ annotation_custom(rast , 1 , 10 , 1 , 9 ) +
108+ scale_x_continuous(transform = " log10" , limits = c(0.1 , 100 ), expand = FALSE ) +
109+ scale_y_continuous(limits = c(0 , 10 ), expand = FALSE )
110+ ann <- get_layer_grob(p )[[1 ]]$ vp
111+
112+ expect_equal(as.numeric(ann $ x ), 1 / 2 )
113+ expect_equal(as.numeric(ann $ y ), 1 / 2 )
114+ expect_equal(as.numeric(ann $ width ), 1 / 3 )
115+ expect_equal(as.numeric(ann $ height ), 8 / 10 )
116+
117+ })
0 commit comments