@@ -47,7 +47,7 @@ test_that("geom_histogram(aes(fill = ..count..)) works", {
4747 }
4848})
4949
50- test_that(" Fixed colour/fill works" , {
50+ test_that(" Histogram with fixed colour/fill works" , {
5151 gg <- base + geom_histogram(colour = " darkgreen" , fill = " white" )
5252 info <- expect_traces(gg , 1 , " fixed-fill-color" )
5353 tr <- info $ traces [[1 ]]
@@ -63,6 +63,69 @@ test_that("Specify histogram binwidth", {
6363 expect_equal(area , 1 , 0.1 )
6464})
6565
66+ test_that(" geom_histogram(aes(fill = factor(...))) is a stacked by default" , {
67+ gg <- base + geom_histogram(aes(fill = factor (vs )))
68+ info <- expect_traces(gg , 2 , " fill-factor" )
69+ trs <- info $ traces
70+ type <- unique(sapply(trs , " [[" , " type" ))
71+ gap <- unique(sapply(trs , " [[" , " bargap" ))
72+ barmode <- unique(sapply(trs , " [[" , " barmode" ))
73+ expect_identical(type , " bar" )
74+ expect_equal(gap , 0 )
75+ expect_equal(barmode , " stack" )
76+ })
77+
78+ test_that(" geom_histogram(aes(fill = factor(...))) respects position_identity()" , {
79+ gg <- base + geom_histogram(aes(fill = factor (vs )), alpha = 0.3 ,
80+ position = " identity" )
81+ info <- expect_traces(gg , 2 , " fill-factor-identity" )
82+ trs <- info $ traces
83+ type <- unique(sapply(trs , " [[" , " type" ))
84+ gap <- unique(sapply(trs , " [[" , " bargap" ))
85+ barmode <- unique(sapply(trs , " [[" , " barmode" ))
86+ expect_identical(type , " bar" )
87+ expect_equal(gap , 0 )
88+ expect_equal(barmode , " overlay" )
89+ })
90+
91+ test_that(" geom_histogram(aes(fill = factor(...))) respects position_dodge()" , {
92+ gg <- base + geom_histogram(aes(fill = factor (vs )), alpha = 0.3 ,
93+ position = " dodge" )
94+ info <- expect_traces(gg , 2 , " fill-factor-dodge" )
95+ trs <- info $ traces
96+ type <- unique(sapply(trs , " [[" , " type" ))
97+ gap <- unique(sapply(trs , " [[" , " bargap" ))
98+ barmode <- unique(sapply(trs , " [[" , " barmode" ))
99+ expect_identical(type , " bar" )
100+ expect_equal(gap , 0 )
101+ expect_equal(barmode , " group" )
102+ })
103+
104+ test_that(" geom_histogram() with facets" , {
105+ gg <- base + geom_histogram(aes(fill = factor (vs )), alpha = 0.3 ) +
106+ facet_wrap(~ am )
107+ info <- expect_traces(gg , 4 , " fill-factor-facets" )
108+ trs <- info $ traces
109+ type <- unique(sapply(trs , " [[" , " type" ))
110+ gap <- unique(sapply(trs , " [[" , " bargap" ))
111+ barmode <- unique(sapply(trs , " [[" , " barmode" ))
112+ expect_identical(type , " bar" )
113+ expect_equal(gap , 0 )
114+ expect_equal(barmode , " stack" )
115+ })
116+
117+ test_that(" vline overlaid histogram" , {
118+ gg <- base + geom_histogram() +
119+ geom_vline(aes(xintercept = mean(wt )), color = " red" , linetype = " dashed" , size = 1 )
120+ info <- expect_traces(gg , 2 , " vline" )
121+ trs <- info $ traces
122+ type <- unique(sapply(trs , " [[" , " type" ))
123+ expect_identical(sort(type ), c(" bar" , " scatter" ))
124+ })
125+
126+
127+
128+
66129# Non-numeric (date) data
67130noram <- data.frame (month = c(" 2012-01-01" , " 2012-02-01" , " 2012-01-01" ,
68131 " 2012-01-01" , " 2012-03-01" , " 2012-02-01" ))
0 commit comments