You can mark points, lines and areas on your chart to emphasise certain things.
Type
You mark things by passing a list
to the
data
argument, this list can be of many different format,
see the official
documentation.
One of the format is to pass a type
:
min
max
avg
max <- list(
name = "Max",
type = "max"
)
min <- list(
name = "Min",
type = "min"
)
avg <- list(
type = "average",
name = "AVG"
)
By default e_mark_*
is applied to all series.
iris |>
group_by(Species) |>
e_charts(Sepal.Length) |>
e_line(Sepal.Width) |>
e_mark_point(data = max) |>
e_mark_point(data = min) |>
e_mark_point(data = avg)
But you can specify one or more serie it should apply apply to.
iris |>
group_by(Species) |>
e_charts(Sepal.Length) |>
e_line(Sepal.Width) |>
e_mark_point(serie = "setosa", data = max) |>
e_mark_point(serie = c("virginica", "setosa"), data = min) |>
e_mark_point(serie = c("virginica", "versicolor"), data = avg)
Custom
library(dplyr)
# get a random point
(
point <- iris |>
filter(Species == "setosa") |>
sample_n(1) |>
select(
xAxis = Sepal.Length,
yAxis = Sepal.Width,
value = Petal.Width
) |>
as.list()
)
#> $xAxis
#> [1] 5.4
#>
#> $yAxis
#> [1] 3.9
#>
#> $value
#> [1] 0.4
iris |>
group_by(Species) |>
e_charts(Sepal.Length) |>
e_line(Sepal.Width) |>
e_mark_point(serie = "setosa", data = point) |>
e_x_axis(min = 4)
Point
iris |>
group_by(Species) |>
e_charts(Sepal.Length) |>
e_line(Sepal.Width) |>
e_mark_point(data = avg) |>
e_x_axis(min = 4)
Line
Horizontally.
iris |>
group_by(Species) |>
e_charts(Sepal.Length) |>
e_line(Sepal.Width) |>
e_mark_line(data = avg) |>
e_x_axis(min = 4)
Vertically.
cars |>
e_charts(speed) |>
e_scatter(dist, symbol_size = 5) |>
e_legend(FALSE) |>
e_mark_line(data = list(xAxis = 7), title = "Tortoise") |>
e_mark_line(data = list(xAxis = 12), title = "Speed Limit") |>
e_mark_line(data = list(xAxis = 22), title = "Need for Speed")