Custom series to display error-bars for scatter, bar or line series
Arguments
- wt
An echarty widget to add error bars to, see ec.init.
- encode
Column selection for both axes (x & y) as vectors, see encode
- hwidth
Half-width of error bar in pixels, default is 6.
- ...
More parameters for custom serie
Details
Command should be called after ec.init where main series are set.
ecr.ebars are custom series, so ec.init(load='custom') is required.
Horizontal and vertical layouts supported, just switch encode values x and y for both for series and ecr.ebars.
Have own default tooltip format showing value, high & low.
Grouped bar series are supported.
Non-grouped series could be shown with formatter riErrBarSimple instead of ecr.ebars. This is limited to vertical only, see example below.
Other limitations:
manually add axis type='category' when needed
error bars cannot have own name when data is grouped
legend select/deselect will not re-position grouped error bars
Examples
library(dplyr)
df <- mtcars |> group_by(cyl,gear) |> summarise(avg.mpg= round(mean(mpg),2)) |>
mutate(low = round(avg.mpg-cyl*runif(1),2),
high= round(avg.mpg+cyl*runif(1),2))
#> `summarise()` has grouped output by 'cyl'. You can override using the `.groups`
#> argument.
ec.init(df, load= 'custom', ctype= 'bar',
xAxis= list(type='category'), tooltip= list(show=TRUE)) |>
ecr.ebars(encode= list(y=c('avg.mpg','low','high'), x='gear'))
#ecr.ebars(encode= list(y=c(3,4,5), x=2)) # ok: data indexes
# same but horizontal
ec.init(df, load= 'custom',
yAxis= list(type='category'), tooltip= list(show=TRUE),
series.param= list(type='bar', encode= list(x='avg.mpg', y='gear') )) |>
ecr.ebars(encode= list(x=c('avg.mpg','low','high'), y='gear'))
# ----- riErrBarSimple ------
df <- mtcars |> mutate(name= row.names(mtcars), hi= hp-drat*3, lo= hp+wt*3) |>
filter(cyl==4) |> select(name,hp,hi,lo)
ec.init(df, load= 'custom', legend= list(show=TRUE)) |>
ec.upd({ series <- append(series, list(
list(type= 'custom', name= 'error',
data= ec.data(df |> select(name,hi,lo)),
renderItem= htmlwidgets::JS('riErrBarSimple')
)))
})
#> Error in select(df, name, hi, lo): Can't select columns that don't exist.
#> ✖ Column `name` doesn't exist.