EVOLUTION-MANAGER
Edit File: label_date.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Label date/times</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for label_date {scales}"><tr><td>label_date {scales}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Label date/times</h2> <h3>Description</h3> <p><code>label_date()</code> and <code>label_time()</code> label date/times using date/time format strings. <code>label_date_short()</code> automatically constructs a short format string suffiicient to uniquely identify labels. It's inspired by matplotlib's <a href="https://matplotlib.org/api/dates_api.html#matplotlib.dates.ConciseDateFormatter"><code>ConciseDateFormatter</code></a>, but uses a slightly different approach: <code>ConciseDateFormatter</code> formats "firsts" (e.g. first day of month, first day of day) specially; <code>date_short()</code> formats changes (e.g. new month, new year) specially. </p> <h3>Usage</h3> <pre> label_date(format = "%Y-%m-%d", tz = "UTC") label_date_short(format = c("%Y", "%b", "%d", "%H:%M"), sep = "\n") label_time(format = "%H:%M:%S", tz = "UTC") date_format(format = "%Y-%m-%d", tz = "UTC") time_format(format = "%H:%M:%S", tz = "UTC") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>format</code></td> <td> <p>For <code>date_format()</code> and <code>time_format()</code> a date/time format string using standard POSIX specification. See <code><a href="../../base/html/strptime.html">strptime()</a></code> for details. </p> <p>For <code>date_short()</code> a character vector of length 4 giving the format components to use for year, month, day, and hour respectively.</p> </td></tr> <tr valign="top"><td><code>tz</code></td> <td> <p>a time zone name, see <code><a href="../../base/html/timezones.html">timezones()</a></code>. Defaults to UTC</p> </td></tr> <tr valign="top"><td><code>sep</code></td> <td> <p>Separator to use when combining date formats into a single string.</p> </td></tr> </table> <h3>Value</h3> <p>All <code>label_()</code> functions return a "labelling" function, i.e. a function that takes a vector <code>x</code> and returns a character vector of <code>length(x)</code> giving a label for each input value. </p> <p>Labelling functions are designed to be used with the <code>labels</code> argument of ggplot2 scales. The examples demonstrate their use with x scales, but they work similarly for all scales, including those that generate legends rather than axes. </p> <h3>Old interface</h3> <p><code>date_format()</code> and <code>time_format()</code> are retired; please use <code>label_date()</code> and <code>label_time()</code> instead. </p> <h3>Examples</h3> <pre> date_range <- function(start, days) { start <- as.POSIXct(start) c(start, start + days * 24 * 60 * 60) } two_months <- date_range("2020-05-01", 60) demo_datetime(two_months) demo_datetime(two_months, labels = date_format("%m/%d")) # ggplot2 provides a short-hand: demo_datetime(two_months, date_labels = "%m/%d") # An alternative labelling system is label_date_short() demo_datetime(two_months, date_breaks = "7 days", labels = label_date_short()) # This is particularly effective for dense labels one_year <- date_range("2020-05-01", 365) demo_datetime(one_year, date_breaks = "month") demo_datetime(one_year, date_breaks = "month", labels = label_date_short()) </pre> <hr /><div style="text-align: center;">[Package <em>scales</em> version 1.1.1 <a href="00Index.html">Index</a>]</div> </body></html>