如何在highchart()图中设置yAxis限制?

苏珊·斯威策(Susan Switzer)

我想通过将y轴的每一侧设置为100%来平衡绘图的外观。我试图应用Highcharts的一些解决方案,但是我正在努力将语法转换为R。

library(highcharter)
categories = c('2015', '2016', '2017', '2018', '2019')
hc <-highchart()%>%
  hc_chart(type= 'bar')%>%
  hc_title(text= 'My Assessment')%>%
  hc_subtitle(text= 'Mathematics')%>%
  hc_legend(enabled = TRUE) %>%
  hc_xAxis(
    list(categories = categories)) %>%
  hc_tooltip(
    shared = FALSE,
    formatter = JS("function () {
                   return this.point.category + '<br/>' +
                   Highcharts.numberFormat(Math.abs(this.point.y), 1);}"))%>%
    hc_yAxis(title = list(
                  text= 'Percent of Students in Performance Levels'),
           labels = list(
                  formatter = JS("function () {
                      return Math.abs(this.value) + '%';
                                    }")))%>%
  hc_plotOptions(series = list(stacking= 'normal'))%>%
  hc_series(
    list(name = 'Not Yet Met',
         data = c(-3, -4, -5, -6,-4), 
         legendIndex = 1),
    list(name = 'Partially Met',
         data = c(-12, -13, -14, -15, -20),
         legendIndex = 2), 
    list(name = 'Approached',
         data= c(-10, -11, -12, -13, -15),
         legendIndex = 3),
    list(name= 'Exceeds',
         data= c(11, 10, 10, 11, 20),
         legendIndex = 5),
    list(name= 'Meets',
         data= c(64, 62, 60, 55, 41),
         legendIndex = 4)
)
hc   

我希望看到在y轴的正向和负向都以100%重新生成图。该图将自动生成负值限制的40%和正值限制的80%。

fmarm

您需要在其中添加minmax参数hc_yAxis

library(highcharter)
categories = c('2015', '2016', '2017', '2018', '2019')
hc <-highchart()%>%
  hc_chart(type= 'bar')%>%
  hc_title(text= 'My Assessment')%>%
  hc_subtitle(text= 'Mathematics')%>%
  hc_legend(enabled = TRUE) %>%
  hc_xAxis(
    list(categories = categories)) %>%
  hc_tooltip(
    shared = FALSE,
    formatter = JS("function () {
                   return this.point.category + '<br/>' +
                   Highcharts.numberFormat(Math.abs(this.point.y), 1);}"))%>%
  hc_yAxis(title = list(
    text= 'Percent of Students in Performance Levels'),
    labels = list(
      formatter = JS("function () {
                      return Math.abs(this.value) + '%';
                                    }")),
    ##### here add min and max
    min=-100,max=100
    )%>%
  hc_plotOptions(series = list(stacking= 'normal'))%>%
  hc_series(
    list(name = 'Not Yet Met',
         data = c(-3, -4, -5, -6,-4), 
         legendIndex = 1),
    list(name = 'Partially Met',
         data = c(-12, -13, -14, -15, -20),
         legendIndex = 2), 
    list(name = 'Approached',
         data= c(-10, -11, -12, -13, -15),
         legendIndex = 3),
    list(name= 'Exceeds',
         data= c(11, 10, 10, 11, 20),
         legendIndex = 5),
    list(name= 'Meets',
         data= c(64, 62, 60, 55, 41),
         legendIndex = 4)
  )
hc   

新图

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章