8000 Add candlestick support by moutikabdessabour · Pull Request #2053 · plotly/plotly.R · GitHub
[go: up one dir, main page]

Skip to content

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added test to showcase the functionality.
  • Loading branch information
moutikabdessabour committed Oct 23, 2021
commit 35b95a84e417042e566a63121438df397723c0ef
5,381 changes: 5,381 additions & 0 deletions tests/testthat/GeomLinerangeBC

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/testthat/GeomLinerangeBC_pars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
list(na.rm = TRUE, flipped_aes = FALSE, na.rm = TRUE, fill_up = "darkblue",
fill_down = "red", colour_up = "darkblue", colour_down = "red",
position = "identity", hoverTextAes = list(x = "date", y = "close",
open = "open", close = "close", high = "high", low = "low"))
5,180 changes: 5,180 additions & 0 deletions tests/testthat/GeomRectCS

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/testthat/GeomRectCS_pars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
list(na.rm = TRUE, na.rm = TRUE, fill_up = "darkblue", fill_down = "red",
colour_up = "darkblue", colour_down = "red", position = "identity",
hoverTextAes = list(x = "date", y = "close", open = "open",
close = "close", high = "high", low = "low"))
1 change: 1 addition & 0 deletions tests/testthat/_snaps/geom-candlestick/geom-candle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions tests/testthat/test-geom-candlestick.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if(require(tidyquant)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use testthat::skip_if_not_installed() instead

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 <- AMZN %>%
ggplot(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")
})
}
0