EVOLUTION-MANAGER
Edit File: aes_colour_fill_alpha.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: Colour related aesthetics: colour, fill, and alpha</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 aes_colour_fill_alpha {ggplot2}"><tr><td>aes_colour_fill_alpha {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Colour related aesthetics: colour, fill, and alpha</h2> <h3>Description</h3> <p>These aesthetics parameters change the colour (<code>colour</code> and <code>fill</code>) and the opacity (<code>alpha</code>) of geom elements on a plot. Almost every geom has either colour or fill (or both), as well as can have their alpha modified. Modifying colour on a plot is a useful way to enhance the presentation of data, often especially when a plot graphs more than two variables. </p> <h3>Colour and fill</h3> <p>Colours and fills can be specified in the following ways: </p> <ul> <li><p> A name, e.g., <code>"red"</code>. R has 657 built-in named colours, which can be listed with <code><a href="../../grDevices/html/colors.html">grDevices::colors()</a></code>. </p> </li> <li><p> An rgb specification, with a string of the form <code>"#RRGGBB"</code> where each of the pairs <code>RR</code>, <code>GG</code>, <code>BB</code> consists of two hexadecimal digits giving a value in the range <code>00</code> to <code>FF</code>. You can optionally make the colour transparent by using the form <code>"#RRGGBBAA"</code>. </p> </li> <li><p> An <code>NA</code>, for a completely transparent colour. </p> </li></ul> <h3>Alpha</h3> <p>Alpha refers to the opacity of a geom. Values of <code>alpha</code> range from 0 to 1, with lower values corresponding to more transparent colors. </p> <p>Alpha can additionally be modified through the <code>colour</code> or <code>fill</code> aesthetic if either aesthetic provides color values using an rgb specification (<code>"#RRGGBBAA"</code>), where <code>AA</code> refers to transparency values. </p> <h3>See Also</h3> <ul> <li><p> Other options for modifying colour: <code><a href="scale_brewer.html">scale_colour_brewer()</a></code>, <code><a href="scale_gradient.html">scale_colour_gradient()</a></code>, <code><a href="scale_grey.html">scale_colour_grey()</a></code>, <code><a href="scale_hue.html">scale_colour_hue()</a></code>, <code><a href="scale_identity.html">scale_colour_identity()</a></code>, <code><a href="scale_manual.html">scale_colour_manual()</a></code>, <code><a href="scale_viridis.html">scale_colour_viridis_d()</a></code> </p> </li> <li><p> Other options for modifying fill: <code><a href="scale_brewer.html">scale_fill_brewer()</a></code>, <code><a href="scale_gradient.html">scale_fill_gradient()</a></code>, <code><a href="scale_grey.html">scale_fill_grey()</a></code>, <code><a href="scale_hue.html">scale_fill_hue()</a></code>, <code><a href="scale_identity.html">scale_fill_identity()</a></code>, <code><a href="scale_manual.html">scale_fill_manual()</a></code>, <code><a href="scale_viridis.html">scale_fill_viridis_d()</a></code> </p> </li> <li><p> Other options for modifying alpha: <code><a href="scale_alpha.html">scale_alpha()</a></code> </p> </li> <li><p> Run <code>vignette("ggplot2-specs")</code> to see an overview of other aesthestics that can be modified. </p> </li></ul> <h3>Examples</h3> <pre> # Bar chart example p <- ggplot(mtcars, aes(factor(cyl))) # Default plotting p + geom_bar() # To change the interior colouring use fill aesthetic p + geom_bar(fill = "red") # Compare with the colour aesthetic which changes just the bar outline p + geom_bar(colour = "red") # Combining both, you can see the changes more clearly p + geom_bar(fill = "white", colour = "red") # Both colour and fill can take an rgb specification. p + geom_bar(fill = "#00abff") # Use NA for a completely transparent colour. p + geom_bar(fill = NA, colour = "#00abff") # Colouring scales differ depending on whether a discrete or # continuous variable is being mapped. For example, when mapping # fill to a factor variable, a discrete colour scale is used. ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) + geom_bar() # When mapping fill to continuous variable a continuous colour # scale is used. ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) # Some geoms only use the colour aesthetic but not the fill # aesthetic (e.g. geom_point() or geom_line()). p <- ggplot(economics, aes(x = date, y = unemploy)) p + geom_line() p + geom_line(colour = "green") p + geom_point() p + geom_point(colour = "red") # For large datasets with overplotting the alpha # aesthetic will make the points more transparent. df <- data.frame(x = rnorm(5000), y = rnorm(5000)) p <- ggplot(df, aes(x,y)) p + geom_point() p + geom_point(alpha = 0.5) p + geom_point(alpha = 1/10) # Alpha can also be used to add shading. p <- ggplot(economics, aes(x = date, y = unemploy)) + geom_line() p yrng <- range(economics$unemploy) p <- p + geom_rect(aes(NULL, NULL, xmin = start, xmax = end, fill = party), ymin = yrng[1], ymax = yrng[2], data = presidential) p p + scale_fill_manual(values = alpha(c("blue", "red"), .3)) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>