# NOT RUN {
## Default sparkline line chart
library(dplyr)
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkline(.))))
## Highlight min and max data points
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(
sepal_length = colDef(cell = react_sparkline(.,
decimals = 1,
highlight_points = highlight_points(min="red",max="blue")))))
## Add labels to data points and change curvature of line
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkline(.,
line_curve = "linear",
decimals = 1,
highlight_points = highlight_points(first="orange",last="blue"),
labels = c("first","last")))))
## Conditionally assign line colors to groups
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
mutate(flower_cols = case_when(
Species == "setosa" ~ "purple",
Species == "versicolor" ~ "darkgreen",
Species == "virginica" ~ "orange",
TRUE ~ "grey"
)) %>%
reactable(.,
columns = list(flower_cols = colDef(show=FALSE),
sepal_length = colDef(cell = react_sparkline(.,
height = 80,
line_color_ref = "flower_cols"))))
## Show area beneath the line
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkline(.,
height = 80,
line_color = "dodgerblue",
show_area = TRUE))))
## Conditionally assign colors to the area below the line
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
mutate(flower_cols = case_when(
Species == "setosa" ~ "purple",
Species == "versicolor" ~ "darkgreen",
Species == "virginica" ~ "orange",
TRUE ~ "grey"
)) %>%
reactable(.,
columns = list(flower_cols = colDef(show=FALSE),
sepal_length = colDef(cell = react_sparkline(.,
height = 80,
show_area = TRUE,
line_color_ref = "flower_cols",
area_color_ref = "flower_cols"))))
## Add bandline to show innerquartile range
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkline(.,
height = 80,
decimals = 1,
highlight_points = highlight_points(max="red"),
labels = c("max"),
bandline = "innerquartiles",
bandline_color = "darkgreen"))))
## Add statline to show the mean for each sparkline
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkline(.,
height = 80,
decimals = 1,
statline = "mean",
statline_color = "red"))))
## Combine multiple elements together
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkline(.,
height = 80,
decimals = 1,
statline = "mean",
statline_color = "red",
bandline = "innerquartiles",
bandline_color = "darkgreen"))))
# }
Run the code above in your browser using DataLab