ecr.ebars | R Documentation |
Custom series to display error-bars for scatter, bar or line series
ecr.ebars(wt, encode = list(x = 1, y = c(2, 3, 4)), hwidth = 6, ...)
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 |
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
A widget with error bars added if successful, otherwise the input widget
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))
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')
)))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.