首页 > 解决方案 > 在带有 highcharter 的图中混合solidguage 和 column

问题描述

我有这两个数据框

1)t1(Var1(数字),Var2(字符串),Freq(数字))

2)pref.media(pref.media(数字)

我有这个分开的图表,但我想在同一个图表中打印两个系列

1)柱形图,ok

column1 <- highchart() %>%
 hc_add_series(t1$Freq, type = "column") %>%
 hc_xAxis(categories = t1$Var1) %>%
 hc_plotOptions(series = list(showInLegend = FALSE,dataLabels = list(enabled = TRUE, color = t1$Var1)))

2) 实心量规图 (ok)

gauge1 <- highchart(width = 800, height = 600) %>%
 hc_chart(type = "solidgauge",backgroundColor = "#F0F0F0",marginTop = 50) %>%
 hc_title(text = "Preferencia",style = list(fontSize = "24px")) %>%
 hc_tooltip(borderWidth = 0, backgroundColor = 'none',shadow = FALSE,style = list(fontSize = '16px')) %>%
 hc_pane(startAngle = -90,endAngle = 90) %>%
 hc_yAxis(min = 0,max = 11,lineWidth = 0,tickPositions = list(0,1,2,3,4,5,6,7,8,9,10,11)) %>%
 hc_plotOptions(solidgauge = list(borderWidth = '34px',dataLabels = list(enabled = TRUE, style = list(borderWidth = 3,backgroundColor = 'none',shadow = FALSE, fontSize = '16px',color="#888800")),linecap = 'round',stickyTracking = FALSE)) %>%
 hc_add_series(name = "Preferencia",borderColor = "#000000",data = list(list(color = "#888800"),radius = "100%",innerRadius = "100%",y =  round(pref.media[[1,1]],2)))

3)混合图表(不好,有错误)

highchart() %>%
 hc_add_series(t1, "column", hcaes(x = Var1, y = Freq), name = "Preferencia") %>%
 hc_add_series(pref.media, "solidgauge", hcaes(name = "Gauge", y = round(pref.media[[1,1]],2)), name = "Indicador") %>%
 hc_plotOptions(
      series = list(showInLegend = FALSE,pointFormat = "{point.y}%"),
      column = list(colorByPoint = TRUE),
      solidgauge = list(borderWidth = '34px',dataLabels = list(enabled = TRUE),linecap = 'round',stickyTracking = FALSE)) %>% 
 hc_pane(startAngle = -90,endAngle = 90) %>%
 hc_yAxis(title = list(text = "Porcentaje de preferencia"),labels = list(format = "{value}%"), max = 100) %>% 
 hc_xAxis(categories = t1$Var1) %>%
 hc_title(text = "Título") %>%
 hc_subtitle(text = "Subtítulo") 

我不明白混合两个系列的顺序。我在http://jkunst.com/highcharter/highcharts.html中使用 J.Kunst 的示例进行了尝试

谢谢

标签: highcharts

解决方案


推荐阅读