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