EVOLUTION-MANAGER
Edit File: labeller.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: Construct labelling specification</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 labeller {ggplot2}"><tr><td>labeller {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Construct labelling specification</h2> <h3>Description</h3> <p>This function makes it easy to assign different labellers to different factors. The labeller can be a function or it can be a named character vectors that will serve as a lookup table. </p> <h3>Usage</h3> <pre> labeller( ..., .rows = NULL, .cols = NULL, keep.as.numeric = NULL, .multi_line = TRUE, .default = label_value ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>Named arguments of the form <code>variable = labeller</code>. Each labeller is passed to <code><a href="as_labeller.html">as_labeller()</a></code> and can be a lookup table, a function taking and returning character vectors, or simply a labeller function.</p> </td></tr> <tr valign="top"><td><code>.rows, .cols</code></td> <td> <p>Labeller for a whole margin (either the rows or the columns). It is passed to <code><a href="as_labeller.html">as_labeller()</a></code>. When a margin-wide labeller is set, make sure you don't mention in <code>...</code> any variable belonging to the margin.</p> </td></tr> <tr valign="top"><td><code>keep.as.numeric</code></td> <td> <p>Deprecated. All supplied labellers and on-labeller functions should be able to work with character labels.</p> </td></tr> <tr valign="top"><td><code>.multi_line</code></td> <td> <p>Whether to display the labels of multiple factors on separate lines. This is passed to the labeller function.</p> </td></tr> <tr valign="top"><td><code>.default</code></td> <td> <p>Default labeller for variables not specified. Also used with lookup tables or non-labeller functions.</p> </td></tr> </table> <h3>Details</h3> <p>In case of functions, if the labeller has class <code>labeller</code>, it is directly applied on the data frame of labels. Otherwise, it is applied to the columns of the data frame of labels. The data frame is then processed with the function specified in the <code>.default</code> argument. This is intended to be used with functions taking a character vector such as <code><a href="../../Hmisc/html/capitalize.html">Hmisc::capitalize()</a></code>. </p> <h3>Value</h3> <p>A labeller function to supply to <code><a href="facet_grid.html">facet_grid()</a></code> or <code><a href="facet_wrap.html">facet_wrap()</a></code> for the argument <code>labeller</code>. </p> <h3>See Also</h3> <p><code><a href="as_labeller.html">as_labeller()</a></code>, <a href="labellers.html">labellers</a> </p> <h3>Examples</h3> <pre> p1 <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point() # You can assign different labellers to variables: p1 + facet_grid( vs + am ~ gear, labeller = labeller(vs = label_both, am = label_value) ) # Or whole margins: p1 + facet_grid( vs + am ~ gear, labeller = labeller(.rows = label_both, .cols = label_value) ) # You can supply functions operating on strings: capitalize <- function(string) { substr(string, 1, 1) <- toupper(substr(string, 1, 1)) string } p2 <- ggplot(msleep, aes(x = sleep_total, y = awake)) + geom_point() p2 + facet_grid(vore ~ conservation, labeller = labeller(vore = capitalize)) # Or use character vectors as lookup tables: conservation_status <- c( cd = "Conservation Dependent", en = "Endangered", lc = "Least concern", nt = "Near Threatened", vu = "Vulnerable", domesticated = "Domesticated" ) ## Source: http://en.wikipedia.org/wiki/Wikipedia:Conservation_status p2 + facet_grid(vore ~ conservation, labeller = labeller( .default = capitalize, conservation = conservation_status )) # In the following example, we rename the levels to the long form, # then apply a wrap labeller to the columns to prevent cropped text idx <- match(msleep$conservation, names(conservation_status)) msleep$conservation2 <- conservation_status[idx] p3 <- ggplot(msleep, aes(x = sleep_total, y = awake)) + geom_point() p3 + facet_grid(vore ~ conservation2, labeller = labeller(conservation2 = label_wrap_gen(10)) ) # labeller() is especially useful to act as a global labeller. You # can set it up once and use it on a range of different plots with # different facet specifications. global_labeller <- labeller( vore = capitalize, conservation = conservation_status, conservation2 = label_wrap_gen(10), .default = label_both ) p2 + facet_grid(vore ~ conservation, labeller = global_labeller) p3 + facet_wrap(~conservation2, labeller = global_labeller) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>