定制DashStyle和颜色,带有R中的hchart功能

定制DashStyle和颜色,带有R中的hchart功能,r,highcharts,r-highcharter,R,Highcharts,R Highcharter,是否有办法在highcharter包中按组关联dashStyle。 我希望以“forecast”作为类型的行是虚线 library(highcharter) # Create sample data frame sample_df <- data_frame(sku = c(rep("12",40)), type = c(rep("actuals",20), rep("forecast",20)),

是否有办法在highcharter包中按组关联dashStyle。 我希望以“forecast”作为类型的行是虚线

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))  %>%
  hc_yAxis(title = list(text = "Units")) %>%  
  hc_xAxis(title = list(text = "Week"), type = "datetime", tickInterval = 7* 24 * 3600 * 1000) %>%
  hc_colors(custom_colours)
库(highcharter)
#创建示例数据帧
样本_df%
hc_xAxis(title=list(text=“Week”),type=“datetime”,tickInterval=7*24*3600*1000)%>%
hc_颜色(自定义_颜色)
此外,是否可以将颜色与组相关联,例如使用带有ifelse的mutate来创建一列,其中包含数据框中的颜色

您可以执行以下操作:

custom_colours <- c("#4286f4", "#d66048")
custom_dashes <- c("Solid", "ShortDashDotDot")

hchart(sample_df, "line",  hcaes(calendar_week, units, group = type),
       color = custom_colours, dashStyle = custom_dashes)  %>%
  hc_yAxis(title = list(text = "Units")) %>%  
  hc_xAxis(title = list(text = "Week"), type = "datetime", tickInterval = 7* 24 * 3600 * 1000)
自定义颜色%
hc_xAxis(title=list(text=“Week”),type=“datetime”,tickInterval=7*24*3600*1000)
您可以执行以下操作:

custom_colours <- c("#4286f4", "#d66048")
custom_dashes <- c("Solid", "ShortDashDotDot")

hchart(sample_df, "line",  hcaes(calendar_week, units, group = type),
       color = custom_colours, dashStyle = custom_dashes)  %>%
  hc_yAxis(title = list(text = "Units")) %>%  
  hc_xAxis(title = list(text = "Week"), type = "datetime", tickInterval = 7* 24 * 3600 * 1000)
自定义颜色%
hc_xAxis(title=list(text=“Week”),type=“datetime”,tickInterval=7*24*3600*1000)

谢谢!如果我错了,请纠正我,但看起来映射顺序是按组的字母顺序排列的?如果分组变量是字符,则是,如果因子是按级别顺序排列的(请尝试使用
sample_df$type谢谢!如果我错了,请纠正我,但映射顺序似乎是按组的字母顺序排列的?如果分组变量是字符,则是,如果因子是按级别顺序排列的(请尝试使用
sample_df$type)