1context("geom_hex") 2 3test_that("density and value summaries are available", { 4 df <- data_frame(x = c(1, 1, 1, 2), y = c(1, 1, 1, 2)) 5 base <- ggplot(df, aes(x, y)) + 6 geom_hex() 7 8 out <- layer_data(base) 9 expect_equal(nrow(out), 2) 10 expect_equal(out$density, c(0.75, 0.25), tolerance = 1e-7) 11 expect_equal(out$count, c(3, 1), tolerance = 1e-7) 12}) 13 14test_that("size and linetype are applied", { 15 df <- data_frame(x = c(1, 1, 1, 2), y = c(1, 1, 1, 2)) 16 plot <- ggplot(df, aes(x, y)) + 17 geom_hex(color = "red", size = 4, linetype = 2) 18 19 gpar <- layer_grob(plot)[[1]]$children[[1]]$gp 20 expect_equal(gpar$lwd, c(4, 4) * .pt, tolerance = 1e-7) 21 expect_equal(gpar$lty, c(2, 2), tolerance = 1e-7) 22}) 23