R HighCharge Errorbar系列位置道奇 [英] R Highcharter Errorbar Series Position Dodge

查看:39
本文介绍了R HighCharge Errorbar系列位置道奇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使错误条正确覆盖在我的分组柱状图上。在gglot中,我会使用position=position_dodge(),但在HighChart的errorbar文档中找不到类似的内容。

这里有一个MWE:

df <- data.frame(Gender = c("Male", "Male", "Female", "Female"),
                 ShareType = rep(c("Long", "Short"),2),
                 InvestedPerAccount = c(10,9,7,8),
                 lower = c(8,7,6,7),
                 upper = c(11.5,10,9,8.8))



highchart() %>%
  hc_add_series(df, "column",hcaes(x = ShareType, y = InvestedPerAccount, group = Gender),
                tooltip = list(enabled = TRUE,pointFormat = '${point.y}')) %>%
  hc_add_series(df, 'errorbar', hcaes(x = ShareType, low = lower, high = upper, group = Gender, grouping = FALSE)) %>%
  hc_xAxis(categories = df$ShareType, title = list(text = "Share Type")) %>% 
  hc_colors(c("pink","lightblue"))

推荐答案

解决方案是在第一组序列中使用id参数,然后在errorbar序列中使用linkedTo。由于"errobar"类型的系列默认情况下链接到上一个类型的系列。

example_dat <- tibble(Type = c("Human", "High-Elf", "Orc"), 
       key = c("World1", "World2", "World3")) %>% 
  expand.grid() %>% 
  mutate(mean = runif(9, 5, 7)) %>% 
  mutate(sd = runif(9, 0, 2)) 


hchart(
  example_dat, 
  "column",
  hcaes(x = key, y = mean, group = Type),
  id = c("a", "b", "c")
  ) %>%
  
  hc_add_series(
    example_dat,
    "errorbar", 
    hcaes(y = mean, x = key, low = mean - sd, high = mean + sd, group = Type),
    linkedTo = c("a", "b", "c"),
    enableMouseTracking = TRUE,
    showInLegend = FALSE
    ) %>% 
  
  hc_plotOptions(
    errorbar = list(
      color = "black", 
      # whiskerLength = 1,
      stemWidth = 1
    ) 
  ) 

这篇关于R HighCharge Errorbar系列位置道奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆