-
Notifications
You must be signed in to change notification settings - Fork 633
/
Copy pathtest-geom-candlestick.R
36 lines (35 loc) · 2.13 KB
/
test-geom-candlestick.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
if(require(tidyquant)){
df <- data.frame(symbol = c("AMZN", "AMZN", "AMZN", "AMZN", "AMZN",
"AMZN", "AMZN", "AMZN", "AMZN", "AMZN", "AMZN", "AMZN", "AMZN",
"AMZN", "AMZN", "AMZN", "AMZN", "AMZN", "AMZN"), date = structure(c(17140,
17141, 17142, 17143, 17144, 17147, 17148, 17149, 17150, 17151,
17154, 17155, 17156, 17157, 17158, 17162, 17163, 17164, 17165
), class = "Date"), open = c(745, 763.98999, 764.549988, 771.869995,
770, 766.400024, 764.960022, 778.25, 766.280029, 765, 758.890015,
768.650024, 770, 768.119995, 764.549988, 763.400024, 776.25,
772.400024, 766.469971), high = c(761.48999, 768.23999, 770.419983,
773.789978, 770.25, 766.890015, 782.460022, 780.859985, 769.099976,
765.130005, 770.5, 774.390015, 771.219971, 771.210022, 766.5,
774.650024, 780, 773.400024, 767.400024), low = c(742, 757.25,
755.820007, 765.190002, 765.340027, 757.200012, 762, 762.809998,
760.309998, 754, 756.159973, 767.710022, 765.700012, 763.02002,
757.98999, 761.200012, 770.5, 760.849976, 748.280029), close = c(759.359985,
764.719971, 770.419983, 767.330017, 768.659973, 760.119995, 774.340027,
768.820007, 761, 757.77002, 766, 771.219971, 770.599976, 766.340027,
760.590027, 771.400024, 772.130005, 765.150024, 749.869995),
volume = c(4314700, 3794700, 3684900, 3189600, 2470900, 2963900,
5285300, 5454800, 3801900, 4848200, 3113200, 2703600, 2044600,
2543600, 1981600, 2638700, 3301000, 3158300, 4139400), adjusted = c(759.359985,
764.719971, 770.419983, 767.330017, 768.659973, 760.119995,
774.340027, 768.820007, 761, 757.77002, 766, 771.219971,
770.599976, 766.340027, 760.590027, 771.400024, 772.130005,
765.150024, 749.869995), stringsAsFactors = F)
test_that("candlestick gets rendered correctly", {
p <- ggplot(df, aes(x = date, y = close)) +
geom_candlestick(aes(open = open, close = close, high = high, low = low)) +
labs(title = "AMZN: New Candlestick Geom!",
x = "", y = "Closing Price") +
coord_x_date(ylim = c(700, 870))
expect_doppelganger(ggplotly(p), "geom-candle")
})
}