2017-12-26 19 views
1

をhighcharter使用して、棒グラフで各バーのための基準線を追加します。は、次のことを好きな私は、各バーのための特定の行を入れたい

enter image description here

しかし、私はできません。これを行うには、私は、少なくとも、特定のテキストを配置するには、次のコードを試してみましたが、それはもう動作しません:

mydata <- data.frame(A=runif(1:10), 
        B=runif(1:10), 
        C=runif(1:10)) 

highchart() %>% 
hc_chart(type = "column", inverted = TRUE) %>% 
hc_title(text = "MyGraph") %>% 
hc_yAxis(title = list(text = "Weights")) %>% 
hc_plotOptions(column = list(
    dataLabels = list(enabled = FALSE), 
    stacking = "normal", 
    enableMouseTracking = FALSE) 
) %>% 
hc_legend(layout="vertical") %>% 
hc_tooltip(formatter = function(){ return("<b> test</b><br/>")}, 
      useHtml = TRUE) %>% 
hc_series(list(name="A",data=mydata$A), 
      list(name="B",data=mydata$B), 
      list(name="C",data=mydata$C)) 

私の質問は、私は各バーラインの棒グラフに赤線を追加する方法ですか?ここで

答えて

2

が可能なソリューションです:

set.seed(1) 
mydata <- data.frame(A=runif(1:10), B=runif(1:10), C=runif(1:10)) 

library(highcharter) 
hc <- highchart() %>% 
hc_chart(type = "column", inverted = TRUE) %>% 
hc_title(text = "MyGraph") %>% 
hc_yAxis(title = list(text = "Weights")) %>% 
hc_plotOptions(column = list(
    dataLabels = list(enabled = FALSE), 
    stacking = "normal", groupPadding=0, 
    enableMouseTracking = FALSE) 
) %>% 
hc_legend(layout="vertical") %>% 
hc_tooltip(formatter = function(){ return("<b> test</b><br/>")}, 
      useHtml = TRUE) %>% 
hc_series(list(name="A",data=mydata$A), 
      list(name="B",data=mydata$B), 
      list(name="C",data=mydata$C)) 

# x position of red lines 
linepos <- c(1.3, 0.7, 1.8, 1.2, 1.0, 1.6, 0.7, 1.7, 0.8, 1.1) 
# height of red lines 
lw <- 0.35 
for (k in 1:length(linepos)) { 
    df <- data.frame(x=c(k-1-lw,k-1+lw),y=rep(linepos[k],2)) 
    hc <- hc %>% 
     hc_add_series(data = df, type = 'line', marker=list(enabled=FALSE), 
      x = ~x, y= ~y, color='red', lineWidth=5, showInLegend=FALSE, 
      enableMouseTracking = FALSE) 
} 
hc 

enter image description here

関連する問題