Skip to contents

This function creates an interactive bar chart visualization using the echarts4r library. The visualization includes interactive features such as data zooming, tooltips, and export options. It supports both light and dark themes through the flg_darkMode parameter.

Usage

create_bar_plot(
  data,
  x_axis_var = "event_month",
  y_axis_var = "n",
  xaxisLabel,
  yaxisLabel,
  title,
  flg_darkMode = FALSE
)

Arguments

data

A data frame containing the data to be plotted.

x_axis_var

x axis variable name from the data.

y_axis_var

y axis variable name from the data.

xaxisLabel

Character string specifying the label for the x-axis.

yaxisLabel

Character string specifying the label for the y-axis.

title

Character string specifying the title of the plot.

flg_darkMode

Logical value (TRUE/FALSE) indicating whether to use dark mode styling. Default is FALSE (light mode).

Value

An echarts4r visualization object that can be displayed in a Shiny app or R Markdown document.

Details

The function provides several interactive features:

  • Data zooming through a slider at the bottom

  • Tooltips showing exact values on hover

  • Option to switch between bar and line representations

  • Export functionality for saving the chart as an image

  • Data view for examining the underlying data

The styling automatically adjusts based on the flg_darkMode parameter, with appropriate color schemes for both light and dark modes.

Examples

# Create sample data
data <- data.frame(
  event_month = month.abb[1:12],
  n = sample(50:100, 12)
)

# Create and display the bar plot
create_bar_plot(
  data = data,
  xaxisLabel = "Month",
  yaxisLabel = "Count",
  title = "Monthly Events",
  flg_darkMode = FALSE
)