business-science / tidyquant

Bringing financial analysis to the tidyverse
https://business-science.github.io/tidyquant/
Other
852 stars 175 forks source link

[geom_barchart|geom_candlestick] Body and Shadow single Width #141

Open N0talent opened 4 years ago

N0talent commented 4 years ago

Hello tidy quant!!

I'm having an issues plotting geom_barchart / geom_candlestick function. Using a Simple code to Test the plot, I plot a barchart but there is no difference in width for the shadow and body.

Code:

AAPL %>%
ggplot(aes(x = date, y = close)) +
geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
geom_ma(color = "darkgreen") +
coord_x_date(xlim = c(today() - weeks(6), today()),
ylim = c(100, 130))

Plot: CandlestickPlot

Im i missing some dependencies? Thank you in advance!

helgasoft commented 4 years ago

This works

AAPL <- tq_get("AAPL", from = "2019-09-01")
AAPL %>% ggplot(aes(x = date, y = close)) +
   geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
   geom_ma(color = "darkgreen") +
   coord_x_date(xlim = c(today() - weeks(8), today()))
antoine-sachet commented 2 years ago

geom_candlestick seems to produce a barplot with a datetime as the x-axis.

The example with AAPL above does work, but stops working if you convert the x-axis to a datetime.

Reprex:

library(tidyquant)
library(dplyr)
library(ggplot2)

AAPL <- tq_get("AAPL", from = "2020-09-01")
#> Warning: `type_convert()` only converts columns of type 'character'.
#> - `df` has no columns of type 'character'
AAPL %>% 
  mutate(date = lubridate::as_datetime(date)) %>% 
  ggplot2::ggplot(aes(x = date, y = close)) +
  geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
  coord_x_datetime(xlim = c(today() - weeks(8), today()))

Created on 2021-09-24 by the reprex package (v2.0.0)