From 4fafc0105f45c7b0abf9658731530a43937b7964 Mon Sep 17 00:00:00 2001 From: pvictor Date: Sat, 16 Feb 2019 19:56:22 +0100 Subject: [PATCH] added labs --- NAMESPACE | 1 + R/labs.R | 45 ++++++++++++++++++++++++++++++++++++++ inst/examples/quick-apex.R | 10 +++++++++ man/ax_labs.Rd | 37 +++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 R/labs.R create mode 100644 man/ax_labs.Rd diff --git a/NAMESPACE b/NAMESPACE index 4229d1a..3f447b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(ax_fill) export(ax_grid) export(ax_labels) export(ax_labels2) +export(ax_labs) export(ax_legend) export(ax_markers) export(ax_plotOptions) diff --git a/R/labs.R b/R/labs.R new file mode 100644 index 0000000..7db417c --- /dev/null +++ b/R/labs.R @@ -0,0 +1,45 @@ + +#' Modify axis, legend, and chart labels +#' +#' @param ax A \code{apexcharts} \code{htmlwidget} object. +#' @param title Text for the title. +#' @param subtitle Text for the subtitle. +#' @param x Text for the x-axis label. +#' @param y Text for the y-axis label. +#' +#' @export +#' +#' @examples +#' meteo_paris <- data.frame( +#' month = month.name, +#' tmax = c(7, 8, 12, 15, 19, 23, 25, 25, 21, 16, 11, 8), +#' tmin = c(3, 3, 5, 7, 11, 14, 16, 16, 13, 10, 6, 3) +#' ) +#' +#' apex(meteo_paris, type = "column", aes(x = month, y = tmin)) %>% +#' ax_labs( +#' title = "Average minimal temperature in Paris", +#' subtitle = "Data from NOAA", +#' x = "Month", +#' y = "Temperature (°C)" +#' ) +ax_labs <- function(ax, title = NULL, subtitle = NULL, x = NULL, y = NULL) { + if (!is.null(title)) { + ax <- ax_title(ax = ax, text = title) + } + if (!is.null(subtitle)) { + ax <- ax_subtitle(ax = ax, text = subtitle) + } + if (!is.null(x)) { + ax <- ax_xaxis(ax = ax, title = list(text = x)) + } + if (!is.null(y)) { + ax <- ax_yaxis(ax = ax, title = list(text = y)) + } + ax +} + + + + + diff --git a/inst/examples/quick-apex.R b/inst/examples/quick-apex.R index 1954cf0..47baa40 100644 --- a/inst/examples/quick-apex.R +++ b/inst/examples/quick-apex.R @@ -58,6 +58,16 @@ apex(data = economics_long, type = "area", mapping = aes(x = date, y = value01, +library(rte.data) + + +consumption <- get_consumption(type = c("REALISED", "D-1")) +apex(data = consumption, type = "line", mapping = aes(x = start_date, y = value, fill = type)) + + + + + # Scatter & Bubble -------------------------------------------------------- diff --git a/man/ax_labs.Rd b/man/ax_labs.Rd new file mode 100644 index 0000000..5f2906e --- /dev/null +++ b/man/ax_labs.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/labs.R +\name{ax_labs} +\alias{ax_labs} +\title{Modify axis, legend, and chart labels} +\usage{ +ax_labs(ax, title = NULL, subtitle = NULL, x = NULL, y = NULL) +} +\arguments{ +\item{ax}{A \code{apexcharts} \code{htmlwidget} object.} + +\item{title}{Text for the title.} + +\item{subtitle}{Text for the subtitle.} + +\item{x}{Text for the x-axis label.} + +\item{y}{Text for the y-axis label.} +} +\description{ +Modify axis, legend, and chart labels +} +\examples{ +meteo_paris <- data.frame( + month = month.name, + tmax = c(7, 8, 12, 15, 19, 23, 25, 25, 21, 16, 11, 8), + tmin = c(3, 3, 5, 7, 11, 14, 16, 16, 13, 10, 6, 3) +) + +apex(meteo_paris, type = "column", aes(x = month, y = tmin)) \%>\% + ax_labs( + title = "Average minimal temperature in Paris", + subtitle = "Data from NOAA", + x = "Month", + y = "Temperature (°C)" + ) +}