带有hchart()函数的R Highcharter tickmarkPlacement

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有hchart()函数的R Highcharter tickmarkPlacement相关的知识,希望对你有一定的参考价值。

看看文档,tickmarkPlacement,似乎允许将刻度从'on'移动到'between'之间,但是使用hchart函数我似乎无法使其工作。

试图从this风格改为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")
答案

tickmarkPlacement仅适用于分类轴。试试这个:

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

以上是关于带有hchart()函数的R Highcharter tickmarkPlacement的主要内容,如果未能解决你的问题,请参考以下文章

R预测autoplot或hchart

带有函数参数的 R 函数

在 R 中使用带有多个参数的匿名函数

HCharts的y轴保留一位和 两位小数

在R中使用带有ff包的apply函数

“类型”在带有 ecdf 对象的 R 绘图函数中不起作用