R highcharter使用形状添加多个注释

时间:2018-07-31 03:33:18

标签: r annotations shapes r-highcharter

我想在Highcharter中添加带有形状的注释

这是我的数据

data <- data.frame(a=c(1:12), b=runif(12, 1, 100))

I want to do this列带有一些注释形状 columns with multiple annotations shapes

我已经参考了Highcharter annotation on date x-axis not working - RHighcharter - add multiple text annotations

但是我仍然做不到,这是我的示例代码

library(highcharter)

hc <- highchart() %>%
  hc_add_series(data, type='column', hcaes(a,b), marker=list(enabled=FALSE))
hc %>% 
  hc_annotations(
    list(
      shapes = list(
        list(
          point = list(
            x = data$a[5],
            y = data$b[5],
            xAxis = 0,
            yAxis = 0
          ),
          type = 'circle'
        )
      )
    )
  )

谢谢您考虑我的要求!

1 个答案:

答案 0 :(得分:3)

尝试一下:

library(highcharter)
data <- data.frame(a=c(1:12), b=runif(12, 1, 100))
hc <- highchart() %>%
  hc_add_series(data, type='column', hcaes(a,b), marker=list(enabled=FALSE))
hc<-hc%>% 
  hc_add_annotation( 
    labels = list(
      list(
        point = list(
          xAxis =0 ,
          yAxis =0 ,
          x =data$a[5],
          y = data$b[5],
          xAxis=0,
          yAxis=0     
        ),
        text = "Is it OK?"
      )
    )
  )

hc%>% 
  hc_add_annotation(
    shapes=list(
      list(
      point=list(
      x=data$a[5],
      y=data$b[5],
      xAxis=0,
      yAxis=0),
      type= 'circle',
      r=10)))

enter image description here