使用Highcharter创建负叠加条形图(Likert图表)

时间:2016-08-02 19:47:09

标签: r highcharts shiny

梦想是Jkunst做出回应,但我正在尝试创建一个带有高图的负叠加条形图,如此处的高图演示 - http://jsfiddle.net/KV5KV/

我尝试过交换所有选项但没有,但我似乎无法一次显示多个系列,如果有人可以帮助它会很棒。以下是我试图在R中运行的内容。

 highchart() %>% 
      hc_chart(type = "bar") %>% 
      hc_title(text = "stuff") %>% 
      hc_yAxis(title = list(text = ""), 
               labels = list(format = "{value}"), min=0) %>% 
      hc_plotOptions(column = list( 
        series=list(stacking='normal'),
        dataLabels = list(enabled = FALSE), 
        enableMouseTracking = TRUE)) %>% 
      hc_legend(enabled = FALSE) %>% 
      hc_xAxis(reversed=FALSE,opposite=TRUE,reversed=FALSE, linkedTo=0) %>% 
      hc_series(list(name="Value",color=c("#766A62"),data=list(-10, -5, -6)))    %>%
      hc_add_series(list(name="Value",color=c("#766A62"),data=list(-2, -5, -3)))  %>%
      hc_add_series(list(name="neutral",id='neutral',color=c("#766A62"),data=list(-2, -5, -3)))  %>%
      hc_add_series(list(name="Value",color=c("#766A62"),data=list(5, 1,6)))  %>%
      hc_add_series(list(name="Value",color=c("#766A62"),data=list(2, 5, 3)))  %>%
      hc_add_series(list(linkedTo='neutral',name="neutral",color=c("#766A62"),data=list(6, 8, 2)))

2 个答案:

答案 0 :(得分:3)

我已经完成了。

highchart() %>% 
  hc_chart(type = "bar") %>% 
  hc_title(text = "Experimental Survey Questions breakdown") %>% 
  hc_yAxis(title = list(text = ""), 
           labels = list(format = "{value}")) %>% 
  hc_plotOptions(series=list(stacking='normal'),column = list( 
    dataLabels = list(enabled = FALSE), 
    enableMouseTracking = TRUE)) %>% 
  hc_legend(enabled = FALSE) %>% 
  hc_xAxis(reversed=FALSE,opposite=TRUE,reversed=FALSE) %>% 
  hc_add_series(name="Value",color=c("rgb(205,35,35)"),data=list(-10, -5, -6))    %>%
  hc_add_series(name="Values",color=c("rgb(165,85,85)"),data=list(-2, -5, -3))  %>%
  hc_add_series(name="neutral",id='neutral',color=c("#766A62"),data=list(-2, -5, -3))  %>%
  hc_add_series(name="Valuess",color=c("rgb(35,35,205)"),data=list(5, 1,6))  %>%
  hc_add_series(name="Valuesss",color=c("rgb(85,85,165)"),data=list(2, 5, 3))  %>%
  hc_add_series(name="Neutral",linkedTo='neutral',color=c("#766A62"),data=list(6, 8, 2))

^为那些寻找答案的人剪切和干燥,特别感谢好的jbkunst,他创造了这个神奇的图书馆并完全改变了我展示我的研究方式(你最好的他们evah wuz;)

我仍然有如何将实际值链接在一起的问题(中性线通过它,这是蹩脚的。)

答案 1 :(得分:1)

我还在摆弄它,但这似乎更接近了。我现在摆脱了颜色。我希望得到镜像的x轴,但如果我能搞清楚的话,我会编辑它。它确实显示了所有3个系列

highchart() %>% 
  hc_chart(type = "bar") %>% 
  hc_title(text = "stuff") %>% 
  hc_yAxis(title = list(text = ""), 
           labels = list(format = "{value}"), min=0) %>% 

  hc_plotOptions(
    series=list(stacking='normal'),
    dataLabels = list(enabled = TRUE), 
    enableMouseTracking = TRUE) %>% 

  hc_legend(enabled = TRUE) %>% 
  hc_xAxis(reversed=FALSE,opposite=TRUE,reversed=FALSE, linkedTo=0) %>% 
  hc_add_series(name="Value", data=list(-10, -5, -6)) %>%
  hc_add_series(name="foo",data=list(-2, -15, -3))  %>%
  hc_add_series(name="neutral",id='neutral',data=list(-2, -5, -4))  %>%
  hc_add_series(name="Value",data=list(5, 1, 7))  %>%
  hc_add_series(name="Value", linkedTo = "neutral", data=list(2, 5, 3))