dreamRs / apexcharter

:bar_chart: R Htmlwidget for ApexCharts.js
https://dreamrs.github.io/apexcharter
Other
138 stars 15 forks source link

Merging two graphical styles within the same graph #26

Closed meandreatta closed 3 years ago

meandreatta commented 3 years ago

This is really more of an enhancement but I think being able to simultaneously view bar and line charts would be a useful addition. I know plotly does this through the add_trace feature so I don't know if a similar aspect could be added here. Otherwise this package is gorgeous, this group continues to impress me with its creativity and design/detail.

pvictor commented 3 years ago

Hello Matthew,

Thanks for your kind words, highly appreciated.

You can add lines on bar charts like this (tis is not on CRAN yet, so install from GitHub):

library(apexcharter)

# Bar ----

data("climate_paris")

# Add a line on a column's chart
apex(climate_paris, aes(month, precipitation), type = "column") %>% 
  add_line(aes(month, temperature))

# Add secondary axis
apex(climate_paris, aes(month, precipitation), type = "column") %>% 
  add_line(aes(month, temperature)) %>%
  ax_yaxis(
    title = list(text = "Precipitation (in mm)")
  ) %>% 
  ax_yaxis2(
    opposite = TRUE,
    decimalsInFloat = 0,
    title = list(text = "Temperature (in degree celsius)")
  ) %>% 
  ax_dataLabels(
    enabled = TRUE, enabledOnSeries = list(1)
  )

image

I will push to CRAN next week if you want to give some feedback in the meantime

Victor

systats commented 3 years ago

Hi Victor, thanks for all your time. I wonder whether it is possible to add a simple line to a candlestick chart? Or to combine a line of stock price with some few decision points on that line (BUY/SELL). Right now I would have to plot the decision points first and than add the price to those few points. Maybe you know where to go next with mixing charts. Thanks in advance, Simon

pvictor commented 3 years ago

In dev version, you can add a line to candlestick, but it mess up with the tooltip... I close this issue, please open a new one to describe what you need.

library(apexcharter)
data("candles", package = "apexcharter")
apex(
  candles, 
  aes(x = datetime, open = open, close = close, low = low, high = high),
  type = "candlestick"
) %>% 
  add_line(aes(datetime, low))