Modify X-Axis of a SveltePlot Chart
sp_x_axis.Rd
Modifies labels, scales, and appearance of the x-axis in a SveltePlot chart. This function allows for customization of the x-axis, including label formatting, scale type (linear or logarithmic), tick marks, and more.
Usage
sp_x_axis(
sp,
title = NULL,
format = NULL,
scale = "linear",
ticks = 6,
label = NULL,
font_size_label = 14,
font_size_ticks = 12,
rotation_axis_ticks = 0,
show_bar_labels = FALSE,
position = "top",
color_ticks = "black",
color_label = "black",
dx = 0,
dy = 0,
text_anchor = NULL,
dominant_baseline = NULL,
trigger = NULL,
linetype = "solid"
)
Arguments
- sp
A SveltePlot htmlwidget object.
- title
Character string specifying the title of the x-axis. Default is NULL.
- format
Character string specifying the format of the x-axis labels. This should correspond to valid D3 format strings. Default is NULL. Documentation for the formats are here https://d3js.org/d3-format.
- scale
Character string indicating the scale type of the axis. Can be either "linear" or "log" for logarithmic. Default is "linear".
- ticks
Numeric value indicating the suggested number of tick marks. D3 will ultimately decide the exact number of ticks based on this suggestion. Default is 6.
- label
Character string for the label of the x-axis. Default is NULL.
- font_size_label
Numeric value specifying the font size of the x-axis label. Default is 14.
- font_size_ticks
Numeric value specifying the font size of the tick labels on the x-axis. Default is 12.
- rotation_axis_ticks
Numeric value indicating the rotation angle (in degrees) of the x-axis tick labels. Default is 0.
- show_bar_labels
Logical indicating whether to show labels on bars for bar charts. Default is FALSE.
- position
Character string specifying the position of bar labels. Can be either "top" or "middle". Default is "top".
- color_ticks
Character string specifying the color of the tick labels on the x-axis. Default is "black".
- color_label
Character string specifying the color of the x-axis label. Default is "black".
- dx
Numeric shift along the x-axis for the x-axis label positioning. Default is 0.
- dy
Numeric shift along the y-axis for the x-axis label positioning. Default is 0.
- text_anchor
Character string specifying the text-anchor attribute for the x-axis labels and ticks. Can be "start", "middle", or "end". Default is NULL.
- dominant_baseline
Character string specifying the dominant-baseline attribute for the x-axis labels and ticks. Default is NULL.
- trigger
Character string specifying the trigger type for tooltips. Can be "axis" or "single". Default is NULL and trigger is chosen based on x-axis type.
- linetype
Character string specifying the line type for the axis trigger. Can be "solid", "dashed", etc. Default is "solid".
Examples
library(SveltePlots)
sp(
data = economics,
mapping = spaes(x = date, y = unemploy),
type = "line",
tooltip = TRUE,
colors = "red"
) |>
sp_add_series(
data = economics,
mapping = spaes(x = date, y = pce),
type = "line",
tooltip = TRUE,
colors = "green"
) |>
sp_add_series(
data = economics,
mapping = spaes(x = date, y = psavert),
type = "line",
tooltip = FALSE,
colors = "blue"
) |>
sp_x_axis(
format = "%b %Y",
ticks = 4,
label = "Date",
font_size_label = 14,
font_size_ticks = 12,
rotation_axis_ticks = -30
) |>
sp_y_axis(
font_size_label = 14,
font_size_ticks = 12
)