2017-07-19 12 views
1

私は、各列の下にテキスト注釈が必要な積み重ね列プロットを持っています。 1つの注釈を追加する方法しか見つけられませんでした。 2番目の注釈を追加すると、エラーAll arguments must be named listが返されます。残念ながら、私はhc_annotations関数の使い方を知っています。Highcharter - 複数のテキスト注釈を追加

は、ここで私が試した少し作業例とコードのビットです:

hc <- highchart() %>% 
    hc_chart(type = "column") %>% 
    hc_plotOptions(column = list(stacking = "normal")) %>% 
    hc_title(text = "Plot with Annotations", useHTML = TRUE) %>% 
    hc_yAxis(title = "") %>% 
    hc_xAxis(title = "") %>% 
    hc_xAxis(categories = c("A", "B", "C", "D", "E")) 

hc <- hc %>% 
    hc_add_series(name = "S1", data = c(5, 1, 2, 4, 5), 
      dataLabels = list(format='{point.y:,.1f}', align = "center", enabled = TRUE)) 

hc <- hc %>% 
    hc_add_series(name = "S2", data = c(-1, -4, 3, -2, -4), 
      dataLabels = list(format='{point.y:,.1f}', align = "center", enabled = TRUE)) 


##try to add annotations 

#1 
hc <- hc %>% 
    hc_annotations(list(xValue = 0, yValue = -2, title = list(text = '-6 pp'))) 
hc <- hc %>% 
    hc_annotations(list(xValue = 1, yValue = -8, title = list(text = '-5 pp'))) 

#2 - basically the same as #1 
hc <- hc %>% 
    hc_annotations(list(xValue = 0, yValue = -2, title = list(text = '-6 pp'))) %>% 
    hc_annotations(list(xValue = 1, yValue = -8, title = list(text = '-5 pp'))) 

#3 
hc <- hc %>% 
    hc_annotations(list(list(xValue = 0, yValue = -2, title = list(text = '-6 pp')), 
         list(xValue = 0, yValue = -8, title = list(text = '-5 pp'))) 
        ) 

    hc 

私はちょうどここにショーケースのような2つの注釈を使用していました。私の最終的なコードでは、各列の下に1つの注釈が必要です。

答えて

1

既知の問題であり、それは次の機能を解決するためです:使用の

  • hc_add_annotation
  • hc_add_annotations

例:

hc %>% 
    hc_add_annotation(xValue = 0, yValue = -2, title = list(text = '-6 pp')) %>% 
    hc_add_annotation(xValue = 1, yValue = -4.5, title = list(text = '-5 pp')) 

hc %>% 
    hc_add_annotations(
    list(
     list(xValue = 0, yValue = -2, title = list(text = '-6 pp')), 
     list(xValue = 1, yValue = -4.5, title = list(text = '-5 pp')) 
    ) 
    ) 

あるいはさらに良い:

df <- data_frame(
    xValue = c(0, 1), 
    yValue = c(-2, -4.5), 
    title = c("-6pp", "-5pp") 
) 

df <- df %>% 
    mutate(title = map(title, function(x) list(text = x))) 

df 

#> # A tibble: 2 x 3 
#> xValue yValue  title 
#> <dbl> <dbl>  <list> 
#> 1  0 -2.0 <list [1]> 
#> 2  1 -4.5 <list [1]> 

hc %>% 
    hc_add_annotations(df) 

参考:https://github.com/jbkunst/highcharter/issues/171

+1

はどうもありがとうございます! –

関連する問題