-
Notifications
You must be signed in to change notification settings - Fork 632
Add candlestick support #2053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add candlestick support #2053
Changes from all commits
9fb273d
35b95a8
e18b3fc
46203d5
68466fc
47cc776
505b882
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -622,6 +622,16 @@ to_basic.GeomQuantile <- function(data, prestats_data, layout, params, p, ...){ | |
dat | ||
} | ||
|
||
#' @export | ||
to_basic.GeomRectCS <- function(data, ...){ | ||
to_basic.GeomRect(data, ...) | ||
} | ||
#' @export | ||
to_basic.GeomLinerangeBC <- function(data, ...){ | ||
data[, c("xend", "y", "yend")] <- data[, c("x", "ymin", "ymax")] | ||
to_basic.GeomSegment(data, ...) | ||
} | ||
Comment on lines
+625
to
+633
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably do more to come up with better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look into this |
||
|
||
#' @export | ||
to_basic.default <- function(data, prestats_data, layout, params, p, ...) { | ||
data | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
if(require(tidyquant)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
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") | ||
}) | ||
} |