library(apexcharter) library(dplyr) # economics dataset from ggplot2 data("economics", package = "ggplot2") economics <- tail(economics, 50) data("economics_long", package = "ggplot2") economics_long <- economics_long %>% filter(variable %in% c("pce", "pop")) %>% group_by(variable) %>% slice(tail(row_number(), 20))
Classic line:
Spline curve:
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed)) %>% ax_stroke(curve = "smooth")
Steps chart:
Color line with gradient:
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed)) %>% ax_fill( type = "gradient", gradient = list( shade = "dark", gradientToColors = list("#FDD835"), shadeIntensity = 1, type = "horizontal", opacityFrom = 1, opacityTo = 1, stops = c(0, 100, 100, 100) ) )
Solid area color:
apex(data = economics, type = "area", mapping = aes(x = date, y = uempmed)) %>% ax_fill(type = "solid", opacity = 1)
Line width:
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed)) %>% ax_stroke(width = 1)
Dotted line
Add points to line :
apex(data = tail(economics, 20), type = "line", mapping = aes(x = date, y = uempmed)) %>% ax_markers(size = 6)
Add labels over points
apex(data = tail(economics, 20), type = "line", mapping = aes(x = date, y = uempmed)) %>% ax_markers(size = 6) %>% ax_dataLabels(enabled = TRUE)