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, only switch encode values 'x' and 'y', both for series and ecr.ebars.
Grouped bar series are supported.
Have own default tooltip format showing value, high & low.
Non-grouped series could be shown with formatter riErrBarSimple instead of ecr.ebars. See example below.
Limitations:
manually add axis type='category' if 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(yy= round(mean(mpg),2)) |>
mutate(low= round(yy-cyl*runif(1),2), high= round(yy+cyl*runif(1),2))
ec.init(df, load= 'custom', ctype= 'bar', tooltip= list(show=TRUE),
xAxis= list(type='category')) |>
ecr.ebars(encode= list(y=c(3,4,5), x=2))
# ----- riErrBarSimple ------
df <- mtcars |> mutate(x=1:nrow(mtcars),hi=hp-drat*3, lo=hp+wt*3) |> select(x,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(x,hi,lo)),
renderItem= htmlwidgets::JS('riErrBarSimple')
)))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.