2019-11-26 12:49:03 +01:00
|
|
|
% Generated by roxygen2: do not edit by hand
|
|
|
|
% Please edit documentation in R/format.R
|
|
|
|
\name{format_num}
|
|
|
|
\alias{format_num}
|
|
|
|
\title{Format numbers (with D3)}
|
|
|
|
\usage{
|
2019-11-26 13:09:47 +01:00
|
|
|
format_num(format, prefix = "", suffix = "", locale = "en-US")
|
2019-11-26 12:49:03 +01:00
|
|
|
}
|
|
|
|
\arguments{
|
|
|
|
\item{format}{Format for numbers, currency, percentage, e.g. \code{".0\%"} for rounded percentage.
|
|
|
|
See online documentation : \url{https://github.com/d3/d3-format}.}
|
|
|
|
|
2019-11-27 23:17:23 +01:00
|
|
|
\item{prefix}{Character string to append before formatted value.}
|
2019-11-26 13:09:47 +01:00
|
|
|
|
2019-11-27 23:17:23 +01:00
|
|
|
\item{suffix}{Character string to append after formatted value.}
|
2019-11-26 13:09:47 +01:00
|
|
|
|
2019-11-27 23:17:23 +01:00
|
|
|
\item{locale}{Localization to use, for example \code{"fr-FR"} for french,
|
2019-11-26 12:49:03 +01:00
|
|
|
see possible values here: \url{https://github.com/d3/d3-format/tree/master/locale}.}
|
|
|
|
}
|
|
|
|
\value{
|
|
|
|
a \code{JS} function
|
|
|
|
}
|
|
|
|
\description{
|
|
|
|
Format numbers (with D3)
|
|
|
|
}
|
|
|
|
\examples{
|
|
|
|
# Use SI prefix
|
|
|
|
dat <- data.frame(
|
|
|
|
labels = c("apex", "charts"),
|
|
|
|
values = c(1e4, 2e4)
|
|
|
|
)
|
|
|
|
|
|
|
|
apex(dat, aes(labels, values), "column") \%>\%
|
|
|
|
ax_yaxis(labels = list(
|
|
|
|
formatter = format_num("~s")
|
|
|
|
))
|
|
|
|
|
|
|
|
apex(dat, aes(labels, values * 100), "column") \%>\%
|
|
|
|
ax_yaxis(labels = list(
|
|
|
|
formatter = format_num("~s")
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
# Percentage
|
|
|
|
dat <- data.frame(
|
|
|
|
labels = c("apex", "charts"),
|
|
|
|
values = c(0.45, 0.55)
|
|
|
|
)
|
|
|
|
|
|
|
|
apex(dat, aes(labels, values), "column") \%>\%
|
|
|
|
ax_yaxis(labels = list(
|
|
|
|
formatter = format_num(".0\%")
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
# Currency
|
|
|
|
dat <- data.frame(
|
|
|
|
labels = c("apex", "charts"),
|
|
|
|
values = c(570, 1170)
|
|
|
|
)
|
|
|
|
|
|
|
|
apex(dat, aes(labels, values), "column") \%>\%
|
|
|
|
ax_yaxis(labels = list(
|
|
|
|
formatter = format_num("$,.2f")
|
|
|
|
))
|
|
|
|
|
|
|
|
# Change locale
|
|
|
|
apex(dat, aes(labels, values), "column") \%>\%
|
|
|
|
ax_yaxis(labels = list(
|
2019-11-26 13:09:47 +01:00
|
|
|
formatter = format_num("$,.2f", locale = "fr-FR")
|
2019-11-26 12:49:03 +01:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-26 13:09:47 +01:00
|
|
|
# Customize tooltip value
|
|
|
|
# Use SI prefix
|
|
|
|
dat <- data.frame(
|
|
|
|
labels = c("apex", "charts"),
|
|
|
|
values = c(1e4, 2e4)
|
|
|
|
)
|
2019-11-26 12:49:03 +01:00
|
|
|
|
2019-11-26 13:09:47 +01:00
|
|
|
apex(dat, aes(labels, values), "column") \%>\%
|
|
|
|
ax_tooltip(y = list(
|
|
|
|
formatter = format_num(",", suffix = " GW/h")
|
|
|
|
))
|
2019-11-26 12:49:03 +01:00
|
|
|
|
|
|
|
}
|