Learn R Programming

echarty (version 1.4.7)

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 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(string) of band's lower boundary.

upper

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

type

Type of rendering

  • 'stack' - by two stacked lines

  • 'polygon' - by drawing a polygon as polyline (default). Warning: cannot be zoomed!

...

More parameters for serie

Details

When type='polygon', coordinates of the two boundaries are chained into a polygon and displayed as one.
When type='stack', two stacked lines are drawn, one with customizable areaStyle. The upper boundary coordinates should be values added on top of the lower boundary coordinates.
Type 'stack' needs xAxis to be of type 'category'.

Examples

Run this code
if (interactive()) {
df <- airquality |> mutate(lwr= round(Temp-Wind*2),
                           upr= round(Temp+Wind*2),
                           x= paste0(Month,'-',Day) ) |>
                    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),
              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