Learn R Programming

echarty (version 1.6.3)

ecr.band: Area band

Description

A 'custom' serie with lower and upper boundaries

Usage

ecr.band(df = NULL, lower = NULL, upper = NULL, type = "polygon", ...)

Value

A list of one serie when type='polygon', or list of two series when type='stack'

Arguments

df

A data.frame with lower and upper numerical columns and first column with X coordinates.

lower

The column name of band's lower boundary (string).

upper

The column name of band's upper boundary (string).

type

Type of rendering

  • 'polygon' - by drawing a polygon as polyline from upper/lower points (default)

  • 'stack' - by two stacked lines

...

More attributes for serie

Details

  • type='polygon': coordinates of the two boundaries are chained into one polygon. Tooltips do not show upper band values.
    xAxis type could be 'category' or 'value'.
    Set fill color with attribute color.

  • type='stack': two stacked lines are drawn, the lower with customizable areaStyle.
    xAxis type should be 'category'! Tooltips could include upper band values.
    Set fill color with attribute areaStyle$color.

Optional parameter name, if given, will show up in legend. Legend merges all series with same name into one item.

Examples

Run this code
df <- airquality |> dplyr::mutate(
    lwr= round(Temp-Wind*2),
    upr= round(Temp+Wind*2),
      x= paste0(Month,'-',Day) ) |>
  dplyr::relocate(x, Temp)
bands <- ecr.band(df, 'lwr', 'upr', type='stack',
                  name= 'stak', areaStyle= list(opacity=0.4))
df |> ec.init( load= 'custom',
   legend= list(show= TRUE),
   dataZoom= list(type= 'slider'),
   toolbox= list(feature= list(dataZoom= list(show= TRUE))),
   xAxis= list(type= 'category', boundaryGap= FALSE),
   series= list(
     list(type='line', color='blue', name='line'),
     bands[[1]], bands[[2]]
   ),
   tooltip= list( trigger= 'axis',
     formatter= ec.clmn(
        'high %@line %@low %@',
                  3.3, 1.2, 2.2)
   )  # 3.3= upper_serie_index +.+ index_of_column_inside
)

Run the code above in your browser using DataLab