0

Looking at the documentation, tickmarkPlacement, seems to allow the moving of ticks from 'on' to 'between' but with the hchart function I can't seem to get it to work.

Trying to change from this style to this.

library(highcharter)

# Create sample data frame
sample_df <- data_frame(sku = c(rep("12",40)),
                        type = c(rep("actuals",20), rep("forecast",20)),
                        calendar_week = rep(seq(as.Date("2017-09-08"), as.Date("2018-01-23"), by=7),2),
                        units = round(c(rnorm(11, mean=50, sd=10), rep(0, 9), c(rnorm(20, mean=100, sd=10))),0))

# Create colours vector
custom_colours <- c("#4286f4", "#d66048")

# Chart
hchart(sample_df, "line",  hcaes(calendar_week, units, group = type), color = custom_colours)  %>%
  hc_yAxis(title = list(text = "Units")) %>%  
  hc_xAxis(title = list(text = "Week"), startOfWeek = 5, type = "datetime", tickInterval = 7* 24 * 3600 * 1000, tickmarkPlacement = "between")
tonyk
  • 348
  • 5
  • 22

1 Answers1

1

tickmarkPlacement works for categorized axes only. Try this:

hchart(sample_df, "line",  hcaes(factor(format(sample_df$calendar_week, "%d-%b-%Y")), 
                                 units, group = type), color = custom_colours)  %>%
  hc_yAxis(title = list(text = "Units")) %>%  
  hc_xAxis(title = list(text = "Week"), tickmarkPlacement = "between")

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58