Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

label sterling #15

Draft
wants to merge 3 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(label_pounds)
export(mm_to_inch)
export(scale_colour_continuous_af)
export(scale_colour_discrete_af)
Expand Down
52 changes: 52 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,55 @@ mm_to_inch <- function(x) {
x / 25.4

}



#' Label pounds sterling
#'
#' Label an axis or legend in pounds sterling.
#'
#' @return labelling function
#' @export
#'
#' @examples
#' library(ggplot2)
#'
#' scales::demo_continuous(c(0, 1), breaks = seq(0, 1, 0.1), labels = label_pounds())
#' scales::demo_continuous(c(0, 5000), breaks = seq(0, 5000, 1000), labels = label_pounds())
#' scales::demo_log10(c(1, 1e12), breaks = scales::log_breaks(5, 1e3), labels = label_pounds())
#'
#' set.seed(123)
#'
#' price_data <- data.frame(
#' date = seq(as.Date("2024-05-12"), as.Date("2024-08-12"), by = 1),
#' price = runif(93, 0, 1000)
#' )
#'
#' use_afcharts()
#'
#' p <- ggplot(price_data, aes(x = date, y = price)) +
#' geom_line() +
#' scale_y_continuous(
#' labels = label_pounds(),
#' expand = c(0, 0),
#' breaks = seq(0, 1000, 100),
#' name = "Price (£)"
#' ) +
#' scale_x_date(
#' date_breaks = "1 month",
#' date_labels = "%B %Y",
#' name = ""
#' ) +
#' coord_cartesian(ylim = c(0, 1000))
#'
#' p
label_pounds <- function() {
scales::label_currency(
prefix = "\u00a3",
suffix = "",
big.mark = ",",
decimal.mark = ".",
trim = TRUE,
scale_cut = c(0, k = 1e3, m = 1e6, bn = 1e9, tn = 1e12)
)
}
47 changes: 47 additions & 0 deletions man/label_pounds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.