View source: R/set_axis_text_color.R
set_axis_text_color | R Documentation |
color axis text by specifying color and add legend based on mapping variable
set_axis_text_color(p, colors, mapping, fake_aes = "color", axis = "x")
p |
ggplot object |
colors |
named vector of colors |
mapping |
mapping variable for generating legend |
fake_aes |
fake aes that use to add a invisible layer for generating legend |
axis |
one of 'x', 'y', or 'xy' |
ggplot object
guangchuang yu
require(ggplot2) set.seed(2017-07-04) d <- data.frame(x = letters[1:5], y = rnorm(5), group = sample(c("Control", "Treatment"), 5, replace=TRUE), type = sample(LETTERS[1:2], 5, replace=TRUE) ) cols <- c(A = "red", B = "blue") p <- ggplot(d, aes(x,y)) + geom_col(aes(fill=group)) set_axis_text_color(p, colors=cols, mapping=~type, fake_aes='color')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.