Skip to contents

X-axis options

Usage

ax_xaxis(
  ax,
  type = NULL,
  categories = NULL,
  labels = NULL,
  axisBorder = NULL,
  axisTicks = NULL,
  tickAmount = NULL,
  min = NULL,
  max = NULL,
  range = NULL,
  floating = NULL,
  position = NULL,
  title = NULL,
  crosshairs = NULL,
  tooltip = NULL,
  ...
)

Arguments

ax

An apexchart() htmlwidget object.

type

Character. Available Options : "categories" and "datetime".

categories

Categories are labels which are displayed on the x-axis.

labels

A list of parameters.

axisBorder

A list of parameters.

axisTicks

A list of parameters.

tickAmount

Number of Tick Intervals to show.

min

Lowest number to be set for the x-axis. The graph drawing beyond this number will be clipped off.

max

Highest number to be set for the x-axis. The graph drawing beyond this number will be clipped off.

range

Range takes the max value of x-axis, subtracts the provided range value and gets the min value based on that. So, technically it helps to keep the same range when min and max values gets updated dynamically.

floating

Logical. Floating takes x-axis is taken out of normal flow and places x-axis on svg element directly, similar to an absolutely positioned element. Set the offsetX and offsetY then to adjust the position manually

position

Setting this option allows you to change the x-axis position. Available options: "top" and "bottom".

title

A list of parameters.

crosshairs

A list of parameters.

tooltip

A list of parameters.

...

Additional parameters.

Value

An apexchart() htmlwidget object.

Examples

data("mpg", package = "ggplot2")

# X axis title
apex(
  data = mpg,
  mapping = aes(x = manufacturer)
) %>% 
  ax_xaxis(title = list(text = "Car's manufacturer"))
404030302020101000audiaudichevroletchevroletdodgedodgefordfordhondahondahyundaihyundaijeepjeepland roverland roverlincolnlincolnmercurymercurynissannissanpontiacpontiacsubarusubarutoyotatoyotavolkswagenvolkswagenCar's manufacturer
Download SVG
Download PNG
Download CSV
# force labels to rotate and increase height apex( data = mpg, mapping = aes(x = manufacturer) ) %>% ax_xaxis(labels = list(rotateAlways = TRUE, maxHeight = 180))
404030302020101000audiaudichevroletchevroletdodgedodgefordfordhondahondahyundaihyundaijeepjeepland roverland roverlincolnlincolnmercurymercurynissannissanpontiacpontiacsubarusubarutoyotatoyotavolkswagenvolkswagen
Download SVG
Download PNG
Download CSV
# force to not rotate apex( data = mpg, mapping = aes(x = manufacturer) ) %>% ax_xaxis(labels = list(rotate = 0, trim = FALSE))
404030302020101000audiaudichevroletchevroletfordfordhondahondahyundaihyundailand roverland rovermercurymercurypontiacpontiactoyotatoyotavolkswagenvolkswagen
Download SVG
Download PNG
Download CSV
data("economics", package = "ggplot2") # Custom crosshair apex( data = tail(economics, 50), mapping = aes(x = date, y = psavert), type = "line" ) %>% ax_xaxis( crosshairs = list( opacity = 1, width = 2, fill = list(color = "red"), stroke = list(width = 0) ) )
12.0012.0010.0010.008.008.006.006.004.004.00Jul '11Jul '1120122012Jul '12Jul '1220132013Jul '13Jul '1320142014Jul '14Jul '1420152015
Download SVG
Download PNG
Download CSV
# Date format (zoom to see changes) apex( data = tail(economics, 150), mapping = aes(x = date, y = psavert), type = "line" ) %>% ax_xaxis( labels = list( datetimeFormatter = list( year = "yyyy-MM", month = "yyyy-MM-dd", day = "yyyy-MM-dd HH:mm" ) ) )
12.0012.0010.0010.008.008.006.006.004.004.002.002.002003-112003-112005-012005-012007-012007-012009-012009-012011-012011-012013-012013-01
Download SVG
Download PNG
Download CSV