set_axis_text_color: set_axis_text_color

View source: R/set_axis_text_color.R

set_axis_text_colorR Documentation

set_axis_text_color

Description

color axis text by specifying color and add legend based on mapping variable

Usage

set_axis_text_color(p, colors, mapping, fake_aes = "color", axis = "x")

Arguments

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'

Value

ggplot object

Author(s)

guangchuang yu

Examples

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')

GuangchuangYu/yyplot documentation built on June 17, 2022, 5:34 p.m.