ecr.band {echarty} | R Documentation |
A 'custom' serie with lower and upper boundaries
ecr.band(df = NULL, lower = NULL, upper = NULL, type = "polygon", ...)
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
|
... |
More parameters for serie |
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'.
A list of one serie when type='polygon', or two series when type='stack'
if (interactive()) {
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))
p <- df |> ec.init(load='custom')
p$x$opts$xAxis <- list(type='category', boundaryGap=FALSE)
p$x$opts$series <- list(list(type='line', color='blue', name='line'),
bands[[1]], bands[[2]] )
p$x$opts$tooltip <- list(trigger= 'axis',
formatter= ec.clmn('high <b>%@</b><br>line <b>%@</b><br>low <b>%@</b>',
3.3, 1.2, 2.2)) # 3.3= upper-serie index .index of column inside
p$x$opts$legend <- list(show= TRUE)
p
}